我有以下内容,它从网站加载 XML 并对其进行解析:
function load() {
  xhttp = new XMLHttpRequest();
  xhttp.onreadystatechange = parse;
  xhttp.open('GET', 'http://...XML.xml', false);
  xhttp.send();
}
function parse() {
  xmlDoc = xhttp.responseXML.documentElement.childNodes;
  for (var i = 0; i < xmlDoc.length; i++) {
    nodeName = xmlDoc[i].nodeName;
    ...
}
加载后,我将其存储在 localStorage 中,我可以将其作为字符串检索。我需要能够将其转换回 xml 文档,就像:
xmlDoc = xhttp.responseXML.documentElement.childNodes;
确实如此,所以我可以解析它。我一直在寻找一段时间,无法弄清楚。
提前致谢。