Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6173491
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:35:09+00:00 2026-05-23T23:35:09+00:00

I am trying to parse the abstract part from the XML file. I am

  • 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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T23:35:10+00:00Added an answer on May 23, 2026 at 11:35 pm

    Use ForceContent => 1.

    Or:

    use strict;
    use warnings;
    use feature qw( say );
    
    use LWP::Simple qw( get );
    use XML::LibXML qw( );
    use URI         qw( );
    
    binmode STDOUT, ':encoding(UTF-8)';
    
    my $db = "pubmed";
    my $id = $ARGV[0] || '9915366';
    
    my $url = URI->new('http://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi');
    $url->query_form(
       db      => $db,
       id      => $id,
       retmode => 'xml',
       rettype => 'abstract',
    );
    
    my $xml = get($url);
    
    my $parser = XML::LibXML->new();
    my $doc = $parser->parse_string($xml);
    my $root = $doc->documentElement();
    
    for my $node ($root->findnodes('PubmedArticle/MedlineCitation/Article/Abstract/AbstractText')) {
       say join ':', $node->getAttribute('NlmCategory') // '', $node->textContent();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im trying to parse the XML returned by the Google Geo code API ,but
Im trying to parse a Xml file from a URL, the xml is actually
I trying to parse some xml in Google Refine using Jython and ElementTree but
I trying to parse xml from an inputstream using the sax parser. The inputstream
I'm trying parse the follow XML file: <root>Root <pai>Pai_1 <filho>Pai1,Filho1</filho> <filho>Pai1,Filho2</filho> </pai> <pai>Pai_2 <filho>Pai2,Filho1</filho>
Trying to parse some XML but apparently this is too much for a lazy
Trying to parse an XML result from a Web Service, vinquery.com, usually the values
I'm trying parse an xml file and insert it into an mysql database. The
Trying to parse out lat/lon from a google maps rss feed: $file = http://maps.google.com/maps/ms?ie=UTF8&hl=en&vps=1&jsv=327b&msa=0&output=georss&msid=217909142388190116501.000473ca1b7eb5750ebfe;
Whilst trying to parse MS Excel file using POI-HSSF v3.2 I am getting IndexOutOfBoundsException.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.