- function convert_string_to_xml(strXML)
- {
- if (window.ActiveXObject) {
- xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
- xmlDoc.async="false";
- xmlDoc.loadXML(strXML);
- return xmlDoc;
- } else {
- parser=new DOMParser();
- xmlDoc=parser.parseFromString(strXML,"text/xml");
- return xmlDoc;
- }
- }
- function convert_xml_to_string(xmlObject)
- {
- if (window.ActiveXObject) { // for IE
- return xmlObject.xml;
- } else {
- return (new XMLSerializer()).serializeToString(xmlObject);
- }
- }
- IE
- <script type="text/javascript">
- function load_xml_content_string(xmlData) {
- if (window.ActiveXObject) {
- //for IE
- xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
- xmlDoc.async="false";
- xmlDoc.loadXML(xmlData);
- return xmlDoc;
- } else if (document.implementation && document.implementation.createDocument) {
- //for Mozila
- parser=new DOMParser();
- xmlDoc=parser.parseFromString(xmlData,"text/xml");
- return xmlDoc;
- }
- }
- var xmlObject = load_xml_content_string("<employee><age>12</age></employee>");
- var xmlString = xmlObject.xml;
- alert(string);
- </script>
- FF
- <script type="text/javascript">
- function load_xml_content_string(xmlData) {
- if (window.ActiveXObject) {
- //for IE
- xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
- xmlDoc.async="false";
- xmlDoc.loadXML(xmlData);
- return xmlDoc;
- } else if (document.implementation && document.implementation.createDocument) {
- //for Mozila
- parser=new DOMParser();
- xmlDoc=parser.parseFromString(xmlData,"text/xml");
- return xmlDoc;
- }
- }
- var xmlObject = load_xml_content_string("<employee><age>12</age></employee>");
- var xmlString = (new XMLSerializer()).serializeToString(xmlObject);
- alert(xmlString);
- </script>