tags:

views:

347

answers:

1

Hi ,

I need to use YQL (Yahoo Query Language) to perform a cross domain ajax request then bind the XML response into a JSON object and retrieve a value from the XML.

The link shows how this is done using the YQL service as a proxy for cross domain requests: http://ajaxian.com/archives/using-yql-as-a-proxy-for-cross-domain-ajax

For example I'm trying to load the request below:

http://query.yahooapis.com/v1/public/yql?q=select%20woeid%20from%20geo.places%20where%20text%20%3D%20%22London%2C%20UK%2C%20UK%22&format=xml

After which I need to grab the WOEID value from the XML content returned. Is there a way to use similar code to query the XML data returned?

Thanks alot

+1  A: 

What language are you calling from? If you're in PHP you can something like :

$url = "http://query.yahooapis.com/v1/public/yql?q=select%20woeid%20from%20geo.places%20where%20text%20%3D%20%22London%2C%20UK%2C%20UK%22&format=xml"
$data = file_get_contents($url);
$xml = simple_xml_load_file($data);
$woeid = $xml->query->results->place->woeid;

If you're in Javascript, I would recommend using "format=json" since JS handles that better.

Paul Tarjan
I'm looking to do it with javascript specifically jquery... thanks
nav
then `$.getJSON("http://..", function(data) {})` will do nicely
Paul Tarjan