in reply to Re: XML::Simple problems
in thread XML::Simple problems
One of the main reasons is just the flexibility of XML. And the flexibility of Perl.
Say, you have the following XML snippet:
Now, say you get as output the following:<yada hello="world"></yada>
The XML parser/generator functions did nothing wrong, since in XML context both snippets are the same. Well mostly, since most XML parsers are probably very slightly faster parsing the second representation.<yada hello="world"/>
Now take a look in the direction of Perl. You parse some XML data into a hash. Since hashes don't hold ordered data, the order of the output is not guaranteed. Depending on your XML file and how you use it, it might not matter anyway. Let's take a look at a slightly more complex example:
When you read it into a hash of hashes and write it out again, you might get:<bars> <bar beer="Moe's Best" bartender="Moe">Moe's</bar> <bar beer="Unnamed" bartender="Sam">Cheers</bar> </bars>
This would still represent the same dataset. If order is important, you'll have to use arrays. XML::Simple has an option for that.<bars> <bar bartender="Sam" beer="Unnamed">Cheers</bar> <bar beer="Moe's Best" bartender="Moe">Moe's</bar> </bars>
BREW /very/strong/coffee HTTP/1.1 Host: goodmorning.example.com 418 I'm a teapot
|
|---|