in reply to RFC : XML::Generator::FromDTD

FWIW, I use XML::Xerces::DOMParser, and build things that way. I write wrapper classes for each broad category of XML tag I want to generate.

These classes have get/set methods which just manage some anon hashes in my class's instance data. I also have two methods - getXML and parseXML, which output the entire tree and snarf in a new tree, respectively.

getXML essentially converts my perl-friendly hash representation of the XML tree into a Xerces DOM, then returns the text representation. parseXML does the opposite - snarfs into a DOM and moves it into a nice perl hash. I've never used a DTD, so I'm not sure how far my idea would get you on that front. But as far as a way for "methods and stuff to do the tag work for you", I think it works okay.

Out of interest, how can a DTD help me? What does it bring to the table?

--
Ash OS durbatulk, ash OS gimbatul,
Ash OS thrakatulk, agh burzum-ishi krimpatul!
Uzg-Microsoft-ishi amal fauthut burguuli.

Replies are listed 'Best First'.
Re: RFC : XML::Generator::FromDTD
by boo_radley (Parson) on May 21, 2002 at 14:46 UTC
    hagus sez :
    Out of interest, how can a DTD help me? What does it bring to the table?


    I'll quote from the introduction to Learning XML, since it's got a good concise explanation :

    Unambiguous Structure

    XML takes a hard line when it comes to structure. A document should be marked up in such a way that there are no two ways to interpret the names, order and hierarchy of the elements. This vastly resudces errors and code complexity. Programs don't have to take an educated guess or try to fix syntax mistakes the way HTML browsers often do, as there are no surprises of on XML processor creating a different result from another...
    The DTD is a blueprint for document structure. An XML schema can restrict the types of data that are allowed to go inside elements...
    So, before you start writing an XML document, you should consult the corresponding DTD so you know which tags can accept what attributes, and what those attributes should be, which tags need to be empty and so on. When your XML document is parsed, it gets (should get?) validated against whatever DTD is found in the doctype declaration.
    My hope was that, by creating a module that created an object whose methods complied to (or mostly to, I wanted to run it by pm first and see if the idea was viable) a DTD, I could time & effort debugging later on down the road.