XML process coming back via Ajax with E4X?

I am loading some XML via Ajax.

here is the script snippet:

ajaxRequest.onreadystatechange = function()
    {
        if(ajaxRequest.readyState == 4)
        {
            document.getElementById('loading').innerHTML = 'done';
            google_xml = ajaxRequest.responseXML;
            document.getElementById('xml').innerHTML = 'XML: '+google_xml.toXMLString();
        }
    }

      

The page I load is an XML file, the file is loaded because if I alert (ajaxRequest.responseText); I see. But I'm not sure how to handle it as XML I thought the above script is putting the XML as a string in <div id = "xml"> </div> but it doesn't.

I've used E4X to handle XML in ActionScript, but never in JS, can someone please guide me? Thanks!

0


a source to share


3 answers


I'm not sure which browser you are using, but Firefox is currently the only browser with good E4X support .

Although, to expand on this answer, you might want to know about an alternative:



There's a lot of support for parsing XML in the browser, just not with E4X. You can use jQuery and use dataType: XML. See Xml.com/pub/a/

+3


a source


For those following this question:

var x = new XML ('<xml> string value </xml>');



... now your x value is an xml object that you can manipulate with E4X!

+1


a source


Just use xhr.responseXML which is already a DOM-enabled XML object after filling in the request. If the browser supports the XmlHttpRequest object, this should work directly. Also, IIRC, you can use jQuery to wrap the object and use its own search / each method to move the object.

0


a source







All Articles