Quantcast
Channel: XML parsing issue in Perl - Stack Overflow
Viewing all articles
Browse latest Browse all 2

XML parsing issue in Perl

$
0
0

I am trying to parse the abstract part from the XML file. I am using forcearray. I wrote the code but its just working when the abstract is in array and not working when array is not present. This is because when in an array I also use {content} and when not in array the {content} is missing. The code is as follows

use LWP::Simple;use XML::Simple;use Data::Dumper;open (FH, ">:utf8","xmlparsed2.txt");my $db1 = "pubmed";my $query  = "9915366";my $q = 16404398;my $xml = new XML::Simple;$urlxml = "http://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?db=$db1&id=$q&retmode=xml&rettype=abstract";$dataxml = get($urlxml);$data = $xml->XMLin("$dataxml", ForceArray => [qw( MeshHeading Author AbstractText )], ForceContent => 1);print FH Dumper($data);print FH "Abstract: ".join "\n", map {join ":",($_->{NlmCategory},$_->{content})} @{$data->{PubmedArticle}->{MedlineCitation}->{Article}->{Abstract}->{AbstractText}};print FH "\n";print FH "Title: "."$data->{PubmedArticle}->{MedlineCitation}->{Article}->{ArticleTitle}\n";print FH "\n";print FH "MeSH: ".join '$$', map $_->{DescriptorName}{content}, @{$data->{PubmedArticle}->{MedlineCitation}->{MeshHeadingList}->{MeshHeading}};print FH "\n";print FH "Authors: ".join '$$', map {join "",($_->{LastName},$_->{ForeName})} @{$data->{PubmedArticle}{MedlineCitation}{Article}{AuthorList}{Author}};

Well, when in array(replcae $q in $urlxml by $query) I want the abstract with its NlmCategory like Objective: To determine if the long....... For the above code it is giving me the desired output but with hash at the end as follows:

METHODS:Tertiary care outpatient and inpatient rehabilitation center directly attached to a university hospital.:HASH(0x69d0810).

And for the abstract where it is not an array($q in $urlxml) this code doesn't seem to work, probably because there is not content term(I found this in data dumper). I played a bit and it sort of worked if I do something like just $_ for the array but also prints the two ::. In short I want my code to work for both $query and $q. Can you help?


Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images