2

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?

Harry
  • 87,580
  • 25
  • 202
  • 214

3 Answers3

2

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.

Community
  • 1
  • 1
dthrasher
  • 40,656
  • 34
  • 113
  • 139
0
$(xmlNode).html();
strager
  • 88,763
  • 26
  • 134
  • 176
0
var xmlContent = $(xmlNode)

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

acrosman
  • 12,814
  • 10
  • 39
  • 55
  • 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 Nov 30 '09 at 03:39
  • adding .html() to the end will give you the XML as a string. – acrosman Nov 30 '09 at 14:23
  • 1
    not necessarily. With DOM returned from server, I get this error: TypeError: Cannot call method 'replace' of undefined. – Raj Sep 09 '10 at 18:41