- 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>
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。