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

  • Home
  • SEARCH
  • 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 782577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T20:24:26+00:00 2026-05-14T20:24:26+00:00

I want to pull in data using a XML::XPath parser from a XML DB

  • 0

I want to pull in data using a XML::XPath parser from a XML DB file from the Worldbank site. The problem is that I’m not seeing any results in the output. I must be missing something in the code. Ideally, I would like to extract just the death rate statistics from each country XML DB (year and value). I’m using this as part of my input:

http://data.worldbank.org/sites/default/files/countries/en/afghanistan_en.xml

use strict;
use LWP 5.64;
use HTML::ContentExtractor;
use XML::XPath;

my $agent1 = LWP::UserAgent->new;
my $extractor = HTML::ContentExtractor->new();

#Retrieve main Worldbank country site
my $mainlink = "http://data.worldbank.org/country/";
my $page = $agent1->get("$mainlink");
my $fulltext = $page->decoded_content();

#Match to just all available countries in Worldbank
my $country = "";
my @countryList;
if (@countryList = $fulltext =~ m/(http:\/\/data\.worldbank\.org\/country\/.*?")/gi){
    foreach $country(@countryList){
        #Remove " at the end of link
        $country=~s/\"//gi;
        print "\n" . $country;

        #Retrieve each country profile's XML DB file
        my $page = $agent1->get("$country");
        my $fulltext = $page->decoded_content();
        my $XML_DB = "";
        my @countryXMLDBList;

        if (@countryXMLDBList = $fulltext =~ m/(http:\/\/data\.worldbank\.org\/sites\/default\/files\/countries\/en\/.*?\.xml)/gi){
            foreach $XML_DB(@countryXMLDBList){

                my $page = $agent1->get("$XML_DB");
                my $fulltext = $page->decoded_content();
                #print $fulltext; 
                #Use XML XPath parser to find elements related to death rate
                my $xp = XML::XPath->new($fulltext); #my $xp = XML::XPath->new("afghanistan_en.xml"); 
                my $nodeSet = $xp->find("//*");
                if (!$nodeSet->isa('XML::XPath::NodeSet') || $nodeSet->size() == 0) {
                    #No match found
                    print "\nMatch not found!";
                    exit;
                } else {
                    foreach my $node ($nodeSet->get_nodelist){
                        print "\n" . $node->find('country')->string_value;
                        print "\n" . $node->find('indicator')->string_value;
                        print "\n" . $node->find('year')->string_value;
                        print "\n" . $node->find('value')->string_value;
                        exit;
                    }
                }
            }
            #Build line graph based on death rate statistics and output some image file format
        }
    }
}

I am also looking into using the xpath expression “following-sibling”, but not sure how to use it correctly. For example, I have the following set of XML data where I am only interested in pulling siblings directly after the indicator for just death rate data.

<data>
<country id="AFG">Afghanistan</country>
<indicator id="SP.DYN.CDRT.IN">Death rate, crude (per 1,000 people)</indicator>
<year>2006</year>
<value>20.3410000</value>
</data>
−
<data>
<country id="AFG">Afghanistan</country>
<indicator id="SP.DYN.CDRT.IN">Death rate, crude (per 1,000 people)</indicator>
<year>2007</year>
<value>19.9480000</value>
</data>
−
<data>
<country id="AFG">Afghanistan</country>
<indicator id="SP.DYN.CDRT.IN">Death rate, crude (per 1,000 people)</indicator>
<year>2008</year>
<value>19.5720000</value>
</data>
−
<data>
<country id="AFG">Afghanistan</country>
<indicator id="IC.EXP.DOCS">Documents to export (number)</indicator>
<year>2005</year>
<value>7.0000000</value>
</data>
−
<data>
<country id="AFG">Afghanistan</country>
<indicator id="IC.EXP.DOCS">Documents to export (number)</indicator>
<year>2006</year>
<value>12.0000000</value>
</data>
−
<data>
<country id="AFG">Afghanistan</country>
<indicator id="IC.EXP.DOCS">Documents to export (number)</indicator>
<year>2007</year>
<value>12.0000000</value>
</data>

Any help would be much appreciated!!!

  • 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-14T20:24:26+00:00Added an answer on May 14, 2026 at 8:24 pm

    I dont understand the first part of the question — it says that:

    I’m not seeing any results in the
    output. I must be missing something in
    the code.

    However, this is not a question at all. Especially, when there is no input data provided, and no definition of “results”.

    For the second part:

    I am also looking into using the xpath
    expression “following-sibling”, but
    not sure how to use it correctly. For
    example, I have the following set of
    XML data where I am only interested in
    pulling siblings directly after the
    indicator for just death rate data.

    Use the following XPath expressions (supposing that the data elements are children of the top element of the XML document:

    /*/data/indicator[@id = 'SP.DYN.CDRT.IN']/following-sibling::*

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a site that will pull xml nodes into html using
I want to make auto width text area. Using xml to pull the data,
I want to setup a button, that when clicked on will pull data from
I want pull the data from only a specific column, but what Is returned
I want to pull data from a database to display into a ComboBox, and
I have a multidocument application. I want to pull data from each of those
I am trying to pull data using an mysql query that requires that I
Basically, I want to pull data from August to May for a given set
My site (ASP.NET + C#) has FAQ data pull from another site's web service
Let's say I want to connect to https://www.code.com/secure/test.xml and pull all the data. Before

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.