I asked a question yesterday http://stackoverflow.com/questions/657058/perl-xml-simple-retrieveing-attribute link I am using to get the XML:
http://eutils.ncbi.nlm.nih.gov/entrez/eutils/esummary.fcgi?db=pubmed&id=19273512 (1)
http://eutils.ncbi.nlm.nih.gov/entrez/eutils/esummary.fcgi?db=pubmed&id=19291509 (2)
I made very good progress and wrote the following code which loops through the tags and searches for the ones I need. I am looking for 'doi' tag under 'ArticleIds'
foreach $item_node (@{$dataSummary->{DocSum}->{Item}})
{
if($item_node->{Name} eq 'ArticleIds')
{
foreach $item_node1 (@{$item_node->{Item}})
{
if ($item_node1->{Name} eq 'doi')
{
$doi= $item_node1->{content};
last;
}
}
last;
}
}
This code basically searches for ArticleIds tag and then searches subtags under it to find 'doi' tag.
Problem I am having is that when ArticleIds has multiple sub tags under it (as can be seen in (2)) then everything works fine. However, when ArticleIds tag only has ONE subtag under it (as shown in (1)) then there are errors and program just stops.
I am using the Simple Parser and using the dumper I got two results. Here is some part of the dump for link (1)
{ 'Type' => 'List', 'Item' => { 'Type' => 'String', 'content' => '19273512', 'Name' => 'pubmed' }, 'Name' => 'ArticleIds' }
for link (2)
{ 'Type' => 'List', 'Item' => [ { 'Type' => 'String', 'content' => '909564644', 'Name' => 'pii' }, { 'Type' => 'String', 'content' => '10.1080/13506120802676914', 'Name' => 'doi' }, { 'Type' => 'String', 'content' => '19291509', 'Name' => 'pubmed' } ], 'Name' => 'ArticleIds' }
As you can see. when there are multiple tags under ArticleIds then it is being treated as an array, hence the square brackets.
What would someone suggest in a case like this?