Solved

World Bank Data API: Converting links to data?

Posted on 2015-01-01
4
141 Views
Last Modified: 2015-01-19
Hello,

The World Bank website currently allows anyone to use it's worldwide data

In the above page, the World bank provides a basic call structure format. Following this protocol, I have generated links such as:
Surface area (sq. km) of Ethiopia: http://api.worldbank.org/countries/ETH/indicators/AG.SRF.TOTL.K2?MRV=1&Gapfill=Y

Entering the above link into a url, returns the following data:

<wb:data xmlns:wb="http://www.worldbank.org" page="1" pages="1" per_page="50" total="1">
<wb:data>
<wb:indicator id="AG.SRF.TOTL.K2">Surface area (sq. km)</wb:indicator>
<wb:country id="ET">Ethiopia</wb:country>
<wb:date>2014</wb:date>
<wb:value>1104300</wb:value>
<wb:decimal>0</wb:decimal>
</wb:data>
</wb:data>

Open in new window


I'm not a programmer, but all I want to be able to do is grab the <wb:value> of 1104300 above and add it to a webpage, for multiple url links.

E.g my website would have 10 separate pages (one for each country) and on each of these pages would be the label: Surface area (sq. km): alongside the pulled World Bank data from the above url.

How would I approach this?
0
Comment
Question by:dabug80
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 33

Expert Comment

by:shalomc
ID: 40529297
I didn't know that about the world bank :)

You need some code and programming to extract the value from the XML. Which language do your programmers use, or which language is used on you web site?

There are 2 general approaches:
* Do it on the server. If your web site uses ruby code, then the logic of retrieving the links, parsing the XML and displaying it in context, will be written in ruby.

* Do it on the client. You will write Javascript code that runs in the browser to retrieve the links, parse the XML and display it in context.
0
 
LVL 33

Expert Comment

by:shalomc
ID: 40529356
Just checked - you can't do it client-side in Javascript, because the CORS headers are missing on the World Bank API :(
0
 
LVL 33

Accepted Solution

by:
shalomc earned 500 total points
ID: 40529385
Here is a php snippet that does the job

 
<?php 
function httpGet($url)
{
    $ch = curl_init();  
 
    curl_setopt($ch,CURLOPT_URL,$url);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
//  curl_setopt($ch,CURLOPT_HEADER, false); 
    curl_setopt($ch,CURLOPT_ENCODING , "gzip");

    $output=curl_exec($ch);
 
    curl_close($ch);
    return $output;
}
 
 

$xmlString=httpGet("http://api.worldbank.org/countries/ETH/indicators/AG.SRF.TOTL.K2?MRV=1&Gapfill=Y"); 

$xml=simplexml_load_string( $xmlString ) or die("Error: Cannot create object");
// This gets all nodes in namespace wb that is used inside the XML file
$wb = $xml->children("wb",true);
// print_r($wb); 

echo "<p>"; 
echo "country: " . $wb->data[0]->country . "<br>";
echo "Area: " . $wb->data[0]->value; 


?>

Open in new window

0
 
LVL 1

Author Closing Comment

by:dabug80
ID: 40557419
Excellent. Thanks for taking the time to code and explain. Really appreciate it.
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
The purpose of this video is to demonstrate how to set up basic WordPress SEO. This will be demonstrated using a Windows 8 PC. The plugin used will be WordPress SEO by Yoast. Go to your WordPress login page. This will look like the following: myw…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question