/**
* xml工具
* xml对象和String字符串之间的转换
*
///convert string to xml object (将字符串转换成xml对象)
function string2XML(xmlString) {
//所有浏览器统一用这种方式处理(因为高版本的浏览器都支持)
let parser = new DOMParser();
let xmlObject = parser.parseFromString(xmlString, "text/xml");
return xmlObject;
}
//convert xml object to string (将xml对象转换成字符串)
function xml2String(xmlObject) {
//所有浏览器统一用这种方式处理(因为高版本的浏览器都支持)
return (new XMLSerializer()).serializeToString(xmlObject);
}
兼容ie版本
//convert string to xml object
function String2XML(xmlString) {
// for IE
if (window.ActiveXObject) {
var xmlobject = new ActiveXObject("Microsoft.XMLDOM");
xmlobject.async = "false";
xmlobject.loadXML(xmlstring);
return xmlobject;
}
// for other browsers
else {
var parser = new DOMParser();
var xmlobject = parser.parseFromString(xmlstring, "text/xml");
return xmlobject;
}
}
//convert xml object to string
function XML2String(xmlObject) {
// for IE
if (window.ActiveXObject) {
return xmlobject.xml;
}
// for other browsers
else {
return (new XMLSerializer()).serializeToString(xmlobject);
}
}