in reply to Trees in XML

I would do it with XML::Simple; something like (code not tested!!):
use XML::Simple qw(:strict); ... my $h=XMLin('your-xml-code-or-file-name-goes-here', forcearray => [ qw(person) ], keyattr => []);
After this, $h->person[2]->{lastname} would return 'Creer'.
-- 
Ronald Fischer <ynnor@mm.st>

Replies are listed 'Best First'.
Re^2: Trees in XML
by Anonymous Monk on Jun 03, 2008 at 11:30 UTC
    Thanks
    I have tried simple and found that it mangles the order of the XML when I put it into a hash. I am also experimenting with LibXML but as I said, I would really like to use XML::Parser tree style.

    You see what I would like to do is put the returned value (firstnames) into an array which I can then use later, in another part of the perl script.

    So any clues on how to use XML::Parser to obtain th firstnames?

    Many thanks

      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>
        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