Your skill will accomplish
what the force of many cannot
XML::Simple Oddities and/or Philosophyby osunderdog (Deacon)
|on Sep 26, 2005 at 19:32 UTC||Need Help??|
osunderdog has asked for the
wisdom of the Perl Monks concerning the following question:
The other day I ran into a situation where I wanted to add an xml node to an existing xml structure. Initially, I chose to insert the node using XML::Simple. The key was that I needed to ensure that I didn't change the XML structure of the original, other than the addition of a single node. However I quickly realized that the XML structure of the output was not the same as the input to XMLin.
Here is my sample:
Notice that the a node has an attribute on input, however it does not have one on the result. On the other hand, the attribute of node mfg is symmetrical.
With a deadline looming, I ended up using XML::LibXML to read the xml into DOM and then add the node.
This leads to my philosophical question:
If your needs are not so simple, this may not be the mod ule for you. In that case, you might want to read the section on "WHERE TO FROM HERE?".
I guess what I wanted to do was pretty simple....
Also, after reviewing this situation (for this posting) I have further discovered that the behaviour I see is only related to the root node. If the root node has an attribute, it is not translated back to an attribute for the root node.
For example, the following code works as I expect, however the node I want to modify isn't the top node:
Hazah! I'm Employed! (But not necessarily happily employed.)