JavaScript XML和string相互转化实现代码
时间:2021-08-11 08:25:21|栏目:JavaScript代码|点击: 次
复制代码 代码如下:
//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);
}
}
栏 目:JavaScript代码
本文标题:JavaScript XML和string相互转化实现代码
本文地址:http://www.codeinn.net/misctech/166030.html