public
Last active

Use YQL to convert XML to JSON in your sleep

  • Download Gist
gistfile1.htm
HTML
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
<!-- 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>

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.