I am simply trying to retrieve an attribute from XML into my Perl program. However, I am having problems retrieving attributes.
I am using XML::Simple.
I can recover information fine when XML is like this:
<IdList> <Id>17175540</Id> </IdList>
by using this code
$data->{'DocSum'}->{'Id'};
However, when the XML is like this:
<Item Name='Title' Type='String'> Some Title </Item>
I am not getting any data back when using the following code
$data->{'DocSum'}->{'Title'};
BTW, this is the link I am getting the XML from http://eutils.ncbi.nlm.nih.gov/entrez/eutils/esummary.fcgi?db=pubmed&id=19288470
I took the xml from that page you provided, used the entire thing as a string for the argument to XMLin, and had success with
giving the output
This is pretty much the same thing derobert was saying.
Edit:
Rather than assuming the 6th Item element is the one you are after, to print the content of the node where the Name attribute is ‘Title’ (and then break out of the loop since you’ve found what you want):
Of course, this is still only looking at the Item nodes immediately under DocSum, so if you were looking for PubType instead of Title, it wouldn’t be found due to that being a child of the PubTypeList Item node.