Skip to content

Instantly share code, notes, and snippets.

@ydn
Created March 3, 2010 00:34
Show Gist options
  • Save ydn/320165 to your computer and use it in GitHub Desktop.
Save ydn/320165 to your computer and use it in GitHub Desktop.
Use YQL to convert XML to JSON in your sleep
<!-- Use YQL to convert XML to JSON in your sleep -->
<!-- Introduced in YDN blog post: http://developer.yahoo.net/blog/archives/2010/03/yql_code_samples_yql_is_easy_to_use.html -->
<script src="http://yui.yahooapis.com/3.0.0/build/yui/yui-min.js"></script>
<ul>UN Headlines:</ul>
<script>
var Y = new YUI();
function handleResponse ( json ) {
var items = json.query.results.item;
for ( var i = 0; i < items.length; i++ ) {
Y.one( 'ul' ).append( '<li>'+items[i].title+'</li>' );
}
};
// ref: http://developer.yahoo.com/yui/3/node/
Y.use('node', function ( Y ) {
//when the DOM node utility is ready, fetch the data
Y.Get.script( "http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20rss%20where%20url%3D'http%3A%2F%2Fwww.un.org%2Fapps%2Fnews%2Frss%2Frss_top.asp'&format=json&diagnostics=false&callback=handleResponse" );
} );
// run the query in the YQL console: http://developer.yahoo.com/yql/console/?q=select%20*%20from%20rss%20where%20url%3D%27http%3A%2F%2Fwww.un.org%2Fapps%2Fnews%2Frss%2Frss_top.asp%27
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment