Yes, I agree that a comparison chart would be useful. However, it will take some time to gather the information in an exhaustive way.
I will try to be brief and to the point here at this time. But I will try to post a more comprehensive comparison chart sometime soon.
PROS
XML::Twig comparison
XML::Twig is obviosuly an excellent module. The main difference with XML::Pastor is that, while working with XML::Twig, the code needs to know about the 'xml'ness of the data, whereas, while working with XML::Pastor, the program needs to know -almost- nothing about the xmlness of the data. For the user code, XML elements and attributes are just native Perl objects with accessors and/or regular hash and array access.
Another difference with XML::Twig is the ability to validate against the original W3C Schema in XML::Pastor, and this without needing the schema at run time. By the way, schema validation at run time is stunningly fast, because there is no schema parsing necessary.
XML::Simple comparison
In many respects, XML::Pastor goes much with the philosophy of XML::Simple, with one important difference: XML::Pastor has full round-trip binding with XML. This means you can read and write XML with those native Perl objects. With XML::Simple you could do that, but if you have tried anything other than the most trivial, you know you really can't. Really, XML::Simple is useful for reading in a simple config file in xml maybe, but nothing more.
Another comparison with XML::Simple is that, XML::Simple produces one big deep data structure upon parser the XML file. In contrast, XML::Pastor will produce native Perl Objects for each element and attribute with names and methods (accessors and much more) that correspond to the actual data. Nothing stops the monk from coding additional methods for those objects (using the same package names that resulted from code generation), hence building logic around the native object.
Another drawback of XML::Simple is the multiplcity of child elements. In default mode XML::Simple will produce a hash for a single occurence of a given child node, but will produce an array of hashes if that node appears multiple times. This is very annoying. In another mode, it is possible to instruct XML::Simple to produce only arrays for child elements, but then the whole thing becomes quite convoluted.
XML::Simple eleviates this problem by counting on the schema to produce the expected result. In reality, XML::Pastor will always prouduce a special kind of array for this situation => XML::Pastor::NodeArray , which has magical properties. If you access it like a hash or with a method call, it will pass it on to the first element. If you access it like an array, you can too. So, you never need to know.
Another difference with XML::Simple is the XSD schema validation in XML::Pastor. You can't do that with XML::Simple.
CONS
Apart from some pending limitations, the two cons of XML::Pastor are:
-
XML::Pastor requires a W3C XSD Schema to work with.
-
XML::Pastor performs code generation, which could be considered clumsy by some. Note that this could be done at run-time, too, albeit paying a slight performance penalty at code start-up (the generated code will run
equally fast, though.
-
Updated: XML::Pastor will slurp in the entire XML into memory, much like XML::Simple. This is probably not what you want for huge XML documents. You would be better of with XML::Twig or better yet SAX in that case.
-
Currently, XML::Pastor is only good for working with DATA style XML (without mixed mark up). This basically means that an element either contains only text or only child elements, not both mixed. So, XML::Pastor is not good for working with a document written in a markup language such as XHTML, for example.
Cheers,
Ayhan (trinculo)
| [reply] |
Looks nice but, are you planning to support other XML schema languages like Schematron or Relax NG? I'm asking because XSD is so freaking ugly that I always put my digigloves on before touching it ;-)
A side note for psini who considered the OP being a duplicate: It's not. The version in the code section comes with additional code examples.
| [reply] [d/l] |
Schematron and Relax NG are a bunch that I like a lot for checking structure.
Unfortunatly though, neither of these schemas contain enough information for generating the code.
A way of supporting these would be using them just for validation and not for the actual code generation. But that means you would still need an XSD schema for the code generation.
I agree that XSD schemas tend to be utterly ugly. Using a graphical aidfor designing the schema helps a lot. Here's a bunch:
- editix -- freeware
- Oxygen -- Personal/Academic version below $50
- XmlSpy -- The best. But runs only on windoz. Around $500 I think.
| [reply] |
| [reply] |
| [reply] |
First, I'm going to disagree with the anonymonk - it's not spam. It's entirely on-topic. If you don't want to read perl-related news, find another website.
SPAM as a style of advertisement, the same kind employed here. | [reply] |