I have an XML object (loaded using XMLHTTPRequest
's responseXML
). I have modified the object (using jQuery) and would like to store it as text in a string.
There is apparently a simple way to do it in Firefox et al:
var xmlString = new XMLSerializer().serializeToString( doc );
(from rosettacode )
But how does one do it in IE6 and other browsers (without, of course, breaking Firefox)?
XML serialization is the process of converting XML data from its representation in the XQuery and XPath data model, which is the hierarchical format it has in a Db2® database, to the serialized string format that it has in an application.
Xml. Serialization namespace contains several Attribute classes that can be applied to members of a class. For example, if a class contains a member that will be serialized as an XML element, you can apply the XmlElementAttribute attribute to the member.
Parsing and Serialization SerializeToString() : serializes the message and returns it as a string. Note that the bytes are binary, not text; we only use the str type as a convenient container. ParseFromString(data) : parses a message from the given string.
The XML Document Object Model (DOM) class is an in-memory representation of an XML document. The DOM allows you to programmatically read, manipulate, and modify an XML document. The XmlReader class also reads XML; however, it provides non-cached, forward-only, read-only access.
You can use doc.xml in internet exlporer.
You'll get something like this:
function xml2Str(xmlNode) { try { // Gecko- and Webkit-based browsers (Firefox, Chrome), Opera. return (new XMLSerializer()).serializeToString(xmlNode); } catch (e) { try { // Internet Explorer. return xmlNode.xml; } catch (e) { //Other browsers without XML Serializer alert('Xmlserializer not supported'); } } return false; }
Found it here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With