dtddoc step 4: Generating HTML (2/2) - exploring XML | WebReference

dtddoc step 4: Generating HTML (2/2) - exploring XML

dtddoc step 4: Generating HTML

The PHP solution

The DTD parser in PHP is derived from the one in Java, so porting dtddoc is fairly straightforward. File operations are much more C-style in PHP, and iteration with foreach results in more compact and readable code. Availability of sort functions save us from having to manually sort the index, as in Java. Also worth mentioning is that PHP passes data structures by value, not by reference. This is also true with Java, except that Vectors and Hashtables are objects and are therefore passed by reference. Mind your backslashes in function definitions where you intend to modify the incoming data.

Here is the source code.

The Perl package

The Perl solution looks slightly different in parsing the DTD because of the callback approach to reading comments. Other than that the PHP constructs can be translated almost automatically to Perl constructs, carefully replacing $ with $, @, and % for the respective data structures. View the source code.

Differences in implementations

If you tried all three solutions you noticed slight differences that mirror the language's strengths or weaknesses:

Conclusion

We successfully implemented a first version of a DTD documentation tool in three programming languages. More languages might be considered should a DTD parser be available for those. A first documentation effort was completed with RSS version 0.91 and more will follow. I hope this effort will help you to better understand and more quickly identify DTDs that are relevant to your XML or SGML work!


Produced by Michael Claßen

URL: http://www.webreference.com/xml/column68/2.html
Created: Nov 11, 2002
Revised: Nov 11, 2002