Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: XML Parse Change a Value and Write Back

by Arunbear (Parson)
on Nov 02, 2012 at 18:43 UTC ( #1002022=note: print w/ replies, xml ) Need Help??


in reply to XML Parse Change a Value and Write Back

An earlier post that may help: Edit values in XML and Save?


Comment on Re: XML Parse Change a Value and Write Back
Re^2: XML Parse Change a Value and Write Back
by anshumangoyal (Scribe) on Nov 02, 2012 at 19:40 UTC
    The whole Output XML goes into a mess. I just want the output to look how my input is. Isn't there any other choice?
      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.

        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.
      Why not read the post that I linked to? Two other methods were mentioned: 1) XML::Twig 2) search and replace using a regular expression.
        XML Twig is so confusing. Is there any post which explains xml twig in detail? Regexp i cannot use, the parameters are determined by nodes and thus it fails. Can you suggest some good and easy to use module. I have tried hell lot of modules some are good parsers and some are good modifiers but i am unable to find a module which is a good parser as well writer of XML. Be notified I cannot afford to change my output xml parameters locations.
      I just want the output to look how my input is.

      What goes wrong with your subsequent processing if the syntactic layout of your XML changes even though the semantic layout is retained?


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

      RIP Neil Armstrong

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (15)
As of 2014-09-02 19:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (29 votes), past polls