Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^3: XML Parse Change a Value and Write Back

by bart (Canon)
on Nov 02, 2012 at 19:47 UTC ( #1002038=note: print w/ replies, xml ) Need Help??


in reply to Re^2: XML Parse Change a Value and Write Back
in thread XML Parse Change a Value and Write Back

Don't use XML::Simple.

There's ,no easy solution, I think, because there's probably no XML module around that guarantees that the produced attributes are in the same order as they are parsed.

But XML::Simple guarantees almost absolutely nothing, not even that the output will have a similar structure as the input. It may even move data from content to attribute or vice versa. the only guarantee you get on the output of XML::Simple is that XML::Simple will be able to read it back in.


Comment on Re^3: XML Parse Change a Value and Write Back
Replies are listed 'Best First'.
Re^4: XML Parse Change a Value and Write Back
by bitingduck (Chaplain) on Nov 03, 2012 at 01:12 UTC
    You might get by with XML::Treebuilder. You build a tree from the original XML, and use XML::Element to find where you want to insert new elements and insert them, then dump the tree back to a file with the appropriate pretty printing. If I have time later I'll try to post a simple example. It's not as simple as XML::Simple, but it's not as much to wade through as XML::LibXML.
      Treebuilder is again good for parsing and writing the xml but its very difficult to find the node and modify a parameter value.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (15)
As of 2015-07-31 16:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (279 votes), past polls