Friday, April 1, 2011

Parse XML string in jQuery

Some will tell you that you can load an xml string into jQuery and read it. However, I found that I needed to load my string into an XMLDOM object first and then use jQuery. Like this:

   var data = "<Item><Param>Value</Param></Item>";
   var doc = new ActiveXObject("Microsoft.XMLDOM");
   doc.loadXML(data);
   $(doc).find("Item").each(
    function () {
     var param = $(this).find("Param").first().text();
     alert(param);
    }
   );

No comments:

Post a Comment