JavaScript XML和string相互转化

来源:互联网 发布:大脚for mac 7.0 编辑:程序博客网 时间:2024/06/06 08:47
     function String2XML(xmlString) {
03    // for IE
04    if (window.ActiveXObject) {
05      var xmlobject = new ActiveXObject("Microsoft.XMLDOM");
06      xmlobject.async = "false";
07      xmlobject.loadXML(xmlstring);
08      return xmlobject;
09    }
10    // for other browsers
11    else {
12      var parser = new DOMParser();
13      var xmlobject = parser.parseFromString(xmlstring, "text/xml");
14      return xmlobject;
15    }
16  }
17//convert xml object to string
18function XML2String(xmlObject) {
19    // for IE
20    if (window.ActiveXObject) {      
21      return xmlobject.xml;
22    }
23    // for other browsers
24    else {       
25      return (new XMLSerializer()).serializeToString(xmlobject);
26    }
27  }
原创粉丝点击