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

XML Parse Change a Value and Write Back

by anshumangoyal (Scribe)
on Nov 02, 2012 at 18:16 UTC ( #1002019=perlquestion: print w/ replies, xml ) Need Help??
anshumangoyal has asked for the wisdom of the Perl Monks concerning the following question:

I have an XML File. I want to change some values of some parameters which I want to change while parsing the file using XML::Simple Module. Problem is parsing and changing the parameter values is OK, but when I want to write back the file, the whole content changes. I tried all options mentioned in CPAN module for this but none of this is working. I simply want to parse the XML file, change the parameters and write it back in another file. I also dont want to loose any comments etc. Is there any easy way to do that?

Comment on XML Parse Change a Value and Write Back
Re: XML Parse Change a Value and Write Back
by Arunbear (Parson) on Nov 02, 2012 at 18:43 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.

        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.
        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: perlquestion [id://1002019]
Approved by Arunbear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (13)
As of 2014-09-17 13:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (81 votes), past polls