在IE8中运行时替代getElementsByTagNameNS

时间:2016-06-10 16:28:55

标签: javascript internet-explorer-8 xml-namespaces

我正在解析一个简单的XML文件:

<?xml version="1.0" encoding="UTF-8"?>
<w:wordDocument xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml" w:ocxPresent="no" w:embeddedObjPresent="no" w:macrosPresent="no">
  <w:body>
    <w:r>
      <w:t>smpl tag txt</w:t>
    </w:r>
  </w:body>
</w:wordDocument>

以下代码在Chrome和IE11中运行良好,但在IE8中运行不正常,因为不支持getElementsByTagNameNS。

<html>
<body>
<script>

xhttp=new XMLHttpRequest();
xhttp.open("GET", "smpl.xml", false);
xhttp.send();
xml = xhttp.responseXML;

x = xml.getElementsByTagNameNS('http://schemas.microsoft.com/office/word/2003/wordml', 't');    
document.write(x[i].childNodes[0].nodeValue);

</script>
</body>
</html>

是否有替代getElementsByTagNameNS来处理IE8中的命名空间?

0 个答案:

没有答案