两个小function实现XML和string相互转化

  //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);
      }
    }

相关文章:

  • 2021-10-01
  • 2021-08-31
  • 2021-12-24
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-07-05
  • 2021-06-01
  • 2022-12-23
  • 2022-02-07
  • 2021-09-19
  • 2022-12-23
相关资源
相似解决方案