Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re: XML Parse Change a Value and Write Back

by Arunbear (Prior)
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

Replies are listed 'Best First'.
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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1002022]
and not a whimper to be heard...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (6)
As of 2018-06-24 10:20 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (126 votes). Check out past polls.