Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Re^6: RFC: XML::Pastor v0.52 is released - A REVOLUTIONARY way to deal with XML

by aulusoy (Scribe)
on Jun 30, 2008 at 17:49 UTC ( #694787=note: print w/replies, xml ) Need Help??

in reply to Re^5: RFC: XML::Pastor v0.52 is released - A REVOLUTIONARY way to deal with XML
in thread RFC: XML::Pastor v0.52 is released - A revolutionary way to deal with XML

That reminds me another module, called XML::Tie, that we had developed with a colleage of mine. That one naver made it to CPAN but I probably still have the code around if you are interested.

The interesting thing is that I had the same hunch some years back (2002-2003).

XML::Tie would work with all sorts of dark magic to make a DOM tree look like a tree of Perl hashes. In fact, XML::Tie worked very well for reading XML in and dealing with it.

Where XML::Tie failed miserably though, it was when it was time to set values in the DOM. Since the hash made no difference between attributes and child elements, XML::Tie had to take wild guesses to be be able to put the right data in the right XML node in the DOM. The resulting code would still be valid XML, but not necessarily what you had intended it to be (You could see things in an attribute whereas it should have been really in a child element or vice versa.

This sort of thing is fine when it's only your program that reads/writes the XML, but when you have to share it with others, then the nightmare starts. Because usually, there is contract, i.e. schema, to abide by when you deal with the external world. Then XML::Tie was useless.

Code generation from a schema completely solves this problem. You still deal with native Perl objects (with fields in a hash) when you get/set values, but your object knows how to write it into a DOM tree, because it knows which one is an attribute, which one is an element an so on. Furthermore, you can validate against the schema to make sure.

UPDATE: The generated object doesn't know more about the DOM than the tied object. It knows more about the schema. The DOM tells you what is stored as XML. Schema tells you what ought to be.

The down side is that now you are tied, as a programmer, to an XSD schema. Lucikly, it's not that hard to make one up even after the fact.

  • Comment on Re^6: RFC: XML::Pastor v0.52 is released - A REVOLUTIONARY way to deal with XML

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://694787]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (3)
As of 2018-08-21 01:55 GMT
Find Nodes?
    Voting Booth?
    Asked to put a square peg in a round hole, I would:

    Results (197 votes). Check out past polls.