World Bank Data API: Converting links to data?


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:

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

<wb:data xmlns:wb="" page="1" pages="1" per_page="50" total="1">
<wb:indicator id="AG.SRF.TOTL.K2">Surface area (sq. km)</wb:indicator>
<wb:country id="ET">Ethiopia</wb:country>

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?
Who is Participating?
shalomcConnect With a Mentor CTOCommented:
Here is a php snippet that does the job

function httpGet($url)
    $ch = curl_init();  
//  curl_setopt($ch,CURLOPT_HEADER, false); 
    curl_setopt($ch,CURLOPT_ENCODING , "gzip");

    return $output;


$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

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.
Just checked - you can't do it client-side in Javascript, because the CORS headers are missing on the World Bank API :(
dabug80Author Commented:
Excellent. Thanks for taking the time to code and explain. Really appreciate it.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.