spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / experts / xml / column66

dtddoc step 2: Internal data structures

Developer News
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?

Wutka's DTD parser

Wutka's DTD class looks similar to Bourret's, with the addition of a distinguished member identifying the root element. The individual DTDElements, however, have only three members:

membervalue
attributesThe element's attributes.
contentThe element's content.
nameThe element's name.

This restricts navigation to a top-down approach, descending from the root element. For our documentation generation project we would have to derive the parents of a particular element ourselves.

perlSGML's DTDParser

As mentioned earlier, Perl programs make less use of classes, in favor of a more functional programming style around the built-in hash and array data types. The following functions can be invoked on a DTD object:

functionvalue
get_base_children($element)An element's children (content elements).
get_elem_attr($element)An element's attributes.
get_elements($nosort)Returns all elements in a DTD, in sorted or order of appearance.
get_elements_of_attr($attr_name)Retrieve all elements that have an attribute $attr_name defined in the DTD.
get_parents($element)Get all elements that may be a parent of $element.
get_top_elements()Get the top-most elements defined in the DTD. Top-most elements are those elements that cannot be contained within another element or can only be contained within itself.
is_child($element, $child)returns 1 if $child can be a legal child of $element. Otherwise, 0 is returned.
is_element($element)returns 1 if $element is defined in the DTD. Otherwise, 0 is returned.

There are more SGML-specific functions, which have been omitted for brevity. The functions listed above allow for both a top-down navigation of the DTD and a combination of parent and child traversal. All data structures are returned as Perl hashes or arrays, DTD is the only class in this package.

DTD Parser in phpxmlclasses

The PHP DTD parser is designed like Wutka's Java version, with the DTD object having a root element and an array of all elements. Those elements contain:

membervalue
attributesThe element's attributes.
contentAn element's content.
nameAn elements name.

So here too, we would have to construct the parent relationships ourselves. Apart from that, everything needed for our project is present.

Conclusion

The DTD parsers fall into two categories: The ones that simply parse the DTD into a hierarchical structure of arrays or custom objects, and those that additionally provide full parent/child references. All parsers are suitable candidates for dtddoc, so we can choose the implementation language based on our development needs going forward.


Produced by Michael Claßen

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Rolling Out Your Own HTML Application Version Control · HTML 5: Client-side Storage · Working with Ajax Server Extensions
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Wi-Fi Product Watch, November 2009 · Chip Market Recovering From '08 Collapse · Low-Cost Tools to Kickstart Your New Business

URL: http://www.webreference.com/xml/column66/2.html
Created: Oct 14, 2002
Revised: Oct 14, 2002