in reply to (z) Finding an XML element with XML::Simple

You could get to the information more easily if instead of having the name in an element you had it in an attribute. then you could use the keyattr => Name option to have XML::Simple use the attribute as a key to a hash instead of using an array. If the attribute was name (all lower case) then you would not even have to use the option as it is one of the defaults.

As it is I don't think you can avoid the loop.

  • Comment on Re: (z) Finding an XML element with XML::Simple

Replies are listed 'Best First'.
Re: Re: (z) Finding an XML element with XML::Simple
by grantm (Parson) on Dec 05, 2002 at 19:49 UTC

    Actually, you don't have to put it in an attribute - it works just as well from a child element as long as you haven't used forcearray on that element name. I'd recommend calling XMLin something like this:

    my $config = XMLin($filename, keyattr => {picture => 'Name'}, forcearray => ['picture'] );

    Then you could access the required value like this:

    print $config->{pictures}->{picture}->{'test.jpg'}->{Mtime}, "\n";