Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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.


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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (2)
As of 2024-04-26 01:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found