Beefy Boxes and Bandwidth Generously Provided by pair Networks Frank
Syntactic Confectionery Delight
 
PerlMonks  

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

by anshumangoyal (Scribe)
on Nov 02, 2012 at 19:40 UTC ( #1002032=note: print w/ replies, xml ) Need Help??


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

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?


Comment on Re^2: XML Parse Change a Value and Write Back
Re^3: XML Parse Change a Value and Write Back
by bart (Canon) on Nov 02, 2012 at 19:47 UTC
    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.
        Treebuilder is again good for parsing and writing the xml but its very difficult to find the node and modify a parameter value.
Re^3: XML Parse Change a Value and Write Back
by Arunbear (Parson) on Nov 02, 2012 at 23:55 UTC
    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.
Re^3: XML Parse Change a Value and Write Back
by BrowserUk (Pope) on Nov 03, 2012 at 11:51 UTC
    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://1002032]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (9)
As of 2014-04-18 10:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (466 votes), past polls