Welcome to WebmasterWorld Guest from 54.145.208.64

Forum Moderators: open

Message Too Old, No Replies

Best XML parsing solution?

   
3:09 am on Dec 7, 2006 (gmt 0)

10+ Year Member



I've been using AJAX for a while, but I've managed until now to get around the "X" . I've just passed back what I needed from the server and used it as-is.

I'm wondering what the best way people have found to parse returned XML is? Do you use a library, and if so, which? Or is there a straightforward way of creating and parse XML from the responseText that I'm just missing?

Thanks very much!

5:36 am on Dec 7, 2006 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



Short answer is responseXml, following handles various browser quirks

if ( typeof xh.responseXml === 'undefined' ) {
// for mozzila, should not be required, Content-Type text/xml
var parser = new DOMParser();
var doc = parser.parseFromString( xh.responseText, "text/xml" );
var XMLDoc = doc.documentElement;
}
else {
if ( ( xh.responseXml )
&& ( xh.responseXml.documentElement === null )
&& ( xh.responseStream) ) {
xh.responseXml.load( xh.responseStream );
}
var XMLDoc = xh.responseXml.documentElement;
}