in reply to Re^2: Trees in XML
in thread Trees in XML

It is not XML::Simple which is mangling the order; it is the very property of a hash, that you don't have order there. That's the reason why I used forcearray in my example: This makes the person elements go into array instead of a hash, and staying in the same order as in the XML file.

BTW, does the order matter in your example?

-- 
Ronald Fischer <ynnor@mm.st>

Replies are listed 'Best First'.
Re^4: Trees in XML
by Anonymous Monk on Jun 03, 2008 at 12:59 UTC
    I need to keep the parsed file in order as I am parsing out the value of the firstname and using it in a SQL query which then gives me a result which I will place back into the same position as the firstname value. I am aware that this is a complicated procedure and as I said I am a newbie to perl and so I am trying to boil down the solution into smaller, bitesize pieces so that I can learn and understand each step!

    So any clues or explanation would be great

    Thanks

      Is the output you want the same XML document you are reading, with the first name replaced by the result of a query? In that case Tree is probably not the style you want to use. Stream or Subs would be easier to use, at least because they take care of copying the data you don't want to process as is. It still won't be as convenient as a higher-level module though, you will still have to write a bit of code yourself. At least you will have to output back the tags you are processing, and escape the text you want to insert.

      BTW, I have always tried to keep XML::Twig installation as simple as possible, so if you're using perl 5.8.*, you should be able to drop the Twig.pm file from the distribution either in you Perl's library XML directory, or just in a sub-directory named XML of the current directory.