Skip to content

Instantly share code, notes, and snippets.

@morsdyce
Forked from ydn/gist:320165
Created July 7, 2016 08:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save morsdyce/b5c5a307102216af2261820c24c7f65a to your computer and use it in GitHub Desktop.
Save morsdyce/b5c5a307102216af2261820c24c7f65a 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