Christian Heilmann

Another interesting YQL feature: XML with callback (JSON-P-X)

Thursday, July 9th, 2009 at 4:20 pm

Yesterday’s announcement of YQL now supporting insert, update and delete somehow overshadowed another interesting new feature: XML with callback!

XML with callback?

On first glance having a callback parameter on an XML output doesn’t make any sense. The normal use case of callbacks is to turn JSON data into JSON-P so that you can use the data immediately in JavaScript. The reason for XML with callback is to make it easier to use the same data when getting data from the web. Say I want to use YQL to get the images and links of the people I follow from twitter. The YQL statement is:

select * from html where url=”http://twitter.com/codepo8”
and xpath = “//div[@id=’following_list’]”

The XML output of this call is a pretty hefty XML document with all the HTML as an XML node structure.

The JSON (and JSON-P output) is even worse as it gives you a structure of all the elements and their attributes as properties of nested objects:

div: {
id: “following_list”
span: [
{

a: {
href: “/jemimakiss”
hreflang: “en”
rel: “contact”
title: “Jemima Kiss”
img: {
alt: “Jemima Kiss”
height: “24”
src: “http://s3.amazonaws.c…glasto_mini.jpg”
width: “24”
}

}
}

//... and so on …

Converting this back into HTML could be quite an annoying job – not to say slow. This is why YQL now offers the callback parameter for XML. The JSONP-X output as it is called in the YQL changelog makes this task a lot easier by returning a JSON object with the XML as a string:

foo({
“query”:{
count“,
updated“,
“diagnostics”:{
publiclyCallable“,
“url”:{
execution-time“,
content
},
user-time
}

},
“results”:[

Jemima Kiss [...]

]

});

This makes it dead easy to render the results back as HTML:


Nice? I think so!

Tags: , , , , , ,

Share on Mastodon (needs instance)

Share on Twitter

Newsletter

Check out the Dev Digest Newsletter I write every week for WeAreDevelopers. Latest issues:

Dev Digest 146: 🥱 React fatigue 📊 Query anything with SQL 🧠 AI News

Why it may not be needed to learn React, why Deepfake masks will be a big problem and your spirit animal in body fat! 

Dev Digest 147: Free Copilot! Panel: AI and devs! RTO is bad! Pi plays!

Free Copilot! Experts discuss what AI means for devs. Don't trust containers. Mandated RTO means brain drain. And Pi plays Pokemon!

Dev Digest 148: Behind the scenes of Dev Digest & end of the year reports.

In 50 editions of Dev Digest we gave you 2081 resources. Join us in looking back and learn about all the trends this year.

Dev Digest 149: Wordpress break, VW tracking leak, ChatGPT vs Google.

Slowly starting 2025 we look at ChatGPT vs Google, Copilot vs. Cursor and the state of AI crawlers to replace web search…

Dev Digest 150: Shifting manually to AI.

Manual coding is becoming less of a skill. How can we ensure the quality of generated code? Also, unpacking an APK can get you an AI model.

My other work: