I have a Perl script that reads a XML file that doesn’t have content, only attributes in the element.
Like this:
<league>
<game name="bla"/>
</league>
Now I try to get the game attribute ‘name’.
I tried using $xml->{league}->{game}->{name} and $xml->{league}->{game}->['name'] but they are both not working. Something about a hash problem.
Is there anybody who can help me get the value?
Well, from the XML you posted, I get this:
It doesn’t even appear to be a strict/warnings issue because it appears when I comment my USUW out.
But if you have the right tags, this should work:
And if I call
XMLinwithKeepRoot => 1, you’ll find it at:If you are having trouble locating how the data is being read in, do this:
And then use the path to the structures presented.
Note:
should have died with: “Not an ARRAY reference at” even without warnings enabled.
['string']is a reference to an array with the string'string'as the sole element. And, if$xml->{league}{game}were an array, it would have died with a non-numeric error, because strings don’t address arrays.