The stupid question is the question not asked | |
PerlMonks |
Re: Moose, the tree structure of XML and object-oriented inheritance hiearchiesby perigrin (Sexton) |
on Jun 20, 2011 at 20:26 UTC ( [id://910620]=note: print w/replies, xml ) | Need Help?? |
Hey as the author of XML::Toolkit I thought I should reply to what you mentioned on RIC and what you mentioned here.
My experience is that parsing XML into an object model is tricky. The XML InfoSet may look relatively straight forward but really it isn’t. You mention here that XML::Toolkit doesn’t create an inheritance tree mimicking the XML structure and this is intentional. It leads to very brittle parsers. Take for example a document like the following:
How exactly do you model the <div> elements there? Do you have a single class that is a subclass of itself? Do you generate unique Div#Content and Div#Bacon classes? XML::Toolkit decides to go with “neither” and rather than a isa-relationship it uses a has-a relationship. If you feed this snippet into XML::Toolkit you get back a single Div class that has-a text attribute and an optional div attribute. This is a closer mapping to the underlying idea of XML. XML::Toolkit’s approach falls down however when it comes to being more restrictive. XML::Toolkit doesn’t have proper schema support (yet!) and so it can’t know which elements are required and which are optional. It can’t even known if you are only allowed only one of a given element or many. So it guesses, and it always guesses that you’re allowed 0 or more of any element it sees during the generate step. Later when you go to create a new document from the generated classes, any attribute that is empty is suppressed in the output. So to generate the before mentioned example without the #bacon element
Which is a bit more typing than you were looking for, but is still pretty straight forward.
In Section
Meditations
|
|