spacer

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

home / experts / xml / column65

dtddoc step 1: Parsing a DTD

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

Wutka's DTD parser

Wutka's parser works the same way, but using a java.io.Reader in the constructor instead of the extra SAX inputsource parameter:

import java.io.FileReader;
import com.wutka.dtd.DTDParser;
import com.wutka.dtd.DTD;

DTDParser parser = new DTDParser(new FileReader("html4.dtd"));
DTD dtd = parser.parse();

We will examine the different DTD objects in the next article of this series.

perlSGML's DTDParser

The perlSGML library has been around in a stable version for many years, the latest dated September 18, 1997. It has many tools for manipulating SGML documents, and by logical extension XML and DTD formats. perlSGML also includes the previously introduced dtd2html for documenting DTDs.

Traditionally, Perl programs make less use of classes, in favor of a more functional programming style around the built-in hash and array data types. This put aside, reading and parsing a DTD works similar to the Java examples above:

require "dtd.pl";
$FILEHANDLE = open("html4.dtd");
$status = &DTDread_dtd(FILEHANDLE);

If DTDread_dtd() successfully parsed a DTD, it returns 1, otherwise 0. The resulting parsed data structure is held in package scope variables, creating problems for concurrency and thread safety if not handled with care. In the context of handling a single CGI request these problems are not an issue, though.

DTD Parser in phpxmlclasses

PHP can be used in both Java and Perl style in terms of programming. The PHP XML classes, as the name implies, follows a more object-oriented rather than functional paradigm:

include_once("DTD_parser.html");
$r = new URLReader("html4.dtd");
$parser = new DTDparser($r,false);		
$dtd = $parser->parse(true);  

Conclusion

Although code for dealing with DTDs exists in many programming languages, few applications are available, short of SGML/XML editors with built-in DTD support. In the coming weeks we will make use of this code to create a more powerful DTD documentation tool than dtd2html, along the lines of javadoc.


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/column65/2.html
Created: Sep 30, 2002
Revised: Sep 30, 2002