tags:

views:

803

answers:

3

Suppose xmlNode is a XML DOM node, how do you get its xml system independently?

For IE, it is xmlNode.xml; For netscape, it is new XMLSerializer().serializeToString(xmlNode).

In jQuery, is there any built-in method I can leverage?

A: 
$(xmlNode).html();
strager
A: 

I don't know of a native JQuery function to do it, but there's a cross-browser JavaScript way to get XML from an XML DOM node. Look at the xml2Str function in the answer to this Stack Overflow question: Serialize a DOM node to XML text using JavaScript.

dthrasher
+1  A: 
var xmlContent = $(xmlNode)

For a longer explination checkout the IBM developer works article on AJAX with jQuery

acrosman
I don't think that works: the jQuery/$ converts the serialized form into a DOM, but not the other way around. At least I can't get it do to that.
Peter Becker
adding .html() to the end will give you the XML as a string.
acrosman
@acrosman: not necessarily. With DOM returned from server, I get this error: TypeError: Cannot call method 'replace' of undefined.