Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

World Bank Data API: Converting links to data?

Posted on 2015-01-01
4
Medium Priority
?
158 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 2000 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
There’s a good reason for why it’s called a homepage – it closely resembles that of a physical house and the only real difference is that it’s online. Your website’s homepage is where people come to visit you. It’s the family room of your website wh…
The purpose of this video is to demonstrate how to add AdSense Ads to a WordPress Website, and how to set up WordPress to automatically place Ads in Sidebars. This will be demonstrated using a Windows 8 PC. Log into your AdSense account. : Cli…
The purpose of this video is to demonstrate how to Test the speed of a WordPress Website. Site Speed is an important metric of a site’s health. Slow site speed can result in viewers leaving your site quickly and not seeing your content. This…
Suggested Courses

636 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