XML -> JSON Serialization

Tags: .NET, AJAX, Ajax.NET, ASP.NET, JavaScript, JSON, Web 2.0

With the next release of Ajax.NET Professional you will be able to transform any XmlDocument or XmlNode into a JSON object. This is really cool because we have already a lot of xml documents in our web applications. Currently you have to write a custom class or struct where you have to fill the properties or public fields. Now, you simply call the JavaScriptUtil.GetIJavaScriptObjectFromXmlNode method to return a JavaScript object. At http://munich.schwarz-interactive.de/datatype.aspx I have added a new test (Test 32) which will read the RSS from the Google group and display the title and last 10 posts.

My C# server-side source code looks like this:

public static AjaxPro.IJavaScriptObject Test31()
    XmlDocument doc = new XmlDocument();
    return AjaxPro.JavaScriptUtil.GetIJavaScriptObjectFromXmlNode(doc.DocumentElement);

The RSS xml document looks like this:

<rss version="2.0">
        <title>Ajax.NET Professional Google Group</title>
            <title>Re: [ajaxpro] Title of post</title>
            // ...
            // ...

Now, you are able to write JavaScript code like this:

<script type="text/javascript">

function callback(res) {
    var chn = res.value.channel;
    alert("The RSS channel title: " + chn.title + "\r\nLink: " + chn.link);

    var h = [];

    for(var i=0; i<chn.item.length; i++) {
        h.push(chn.item[i].title + "\r\n");



No Comments


In addition to blogging, I am also now using Twitter for quick updates and to share links. Follow me at: DieApfelFamilie