veritas_penang has asked for the wisdom of the Perl Monks concerning the following question:

I just started using PERL 1 week ago and I am a programming newbee. Please Help as my company project is relying on this. The Situation: I would like to open an XML file, in this example is Library.xml and edit the XML document using a specific "ISBN" number. After the ISBN number is found, I would like to change the number of pages for the particular book with the matching "ISBN" number. The Problem: now, I can do the above but, I need to save the updated XML with the same name "library.xml" and also maintaining the XML structure of the original XML document. This is where I am stumped. I have tried using XML::DUMPER, and XML::TWIG and may others but have failed. The output does not reflect the original XML structure. PLease help.
  • Comment on parse, edit and save in the same XML file

Replies are listed 'Best First'.
Re: parse, edit and save in the same XML file
by moritz (Cardinal) on Apr 25, 2012 at 08:17 UTC

    Please show your code that uses XML::Twig, and show us some example XML input and output.

    I also recommend to first write the output to a file with a different name, and only after that succeeded, delete the orignal file and rename the new one. That way your file doesn't get lost if there's an error during processing.

Re: parse, edit and save in the same XML file
by Khen1950fx (Canon) on Apr 25, 2012 at 08:41 UTC
Re: parse, edit and save in the same XML file
by GrandFather (Saint) on Apr 25, 2012 at 08:20 UTC

    We can't help with what we can't see. Show us the code you are having trouble with or, even better, show us a small self contained script that demonstrates the issue. We will need a little data, the expected output and the actual output. See I know what I mean. Why don't you? for help with how to go about that.

    Note that Perl is case sensitive so module names must generally be the correct case. Also note that your urgent problem is not our urgent problem, but the better you ask your question the quicker and better we will answer it. You will save a lot of time by spending some time getting your question and sample code right.

    True laziness is hard work