未捕获的 NotFoundError:无法在“节点"上执行“appendChild":新的子元素为空 [英] Uncaught NotFoundError: Failed to execute 'appendChild' on 'Node': The new child element is null

查看:43
本文介绍了未捕获的 NotFoundError:无法在“节点"上执行“appendChild":新的子元素为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在尝试通过 html 上的 xsl 显示 xml 数据后,我遇到了奇怪的问题.当我在桌面上编译 html 文件时,没有出现任何问题.但是,当我将这些文件上传到我的服务器并编译 html 文件时,我在 Opera 最新版本上收到此错误消息:Uncaught NotFoundError: Failed to execute 'appendChild' on 'Node': The new child element is null"

I get weird issue after trying to display xml data through xsl on html. when I compile the html file on my desktop, no issue shows up. However, when I upload these files to my server and compile the html file, I get this error message on Opera latest version: "Uncaught NotFoundError: Failed to execute 'appendChild' on 'Node': The new child element is null"

在 FF 上运行时,我也遇到类似的问题:NS_ERROR_ILLEGAL_VALUE:组件返回故障代码:0x80070057 (NS_ERROR_ILLEGAL_VALUE) [nsIXSLTProcessor.importStylesheet]".

I also get similar issue when run that on FF says "NS_ERROR_ILLEGAL_VALUE: Component returned failure code: 0x80070057 (NS_ERROR_ILLEGAL_VALUE) [nsIXSLTProcessor.importStylesheet]".

它与我正在使用的 w3school 中的代码完全相同,但令人惊讶的是,这个问题在我身边发生了......

it is exact same code from w3school I'm using, but surprisingly this issue on my side happening...

您可以找到代码完整代码 XSLT - 在客户端

xml 文件::

<?xml version="1.0" encoding="UTF-8"?>
<catalog>
  <cd>
    <title>Empire Burlesque</title>
    <artist>Bob Dylan</artist>
    <country>USA</country>
    <company>Columbia</company>
    <price>10.90</price>
    <year>1985</year>
  </cd>
.
.
</catalog> 

xsl 文件::

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
  <html>
  <body>
  <h2>My CD Collection</h2>
  <table border="1">
    <tr bgcolor="#9acd32">
      <th style="text-align:left">Title</th>
      <th style="text-align:left">Artist</th>
    </tr>
    <xsl:for-each select="catalog/cd">
    <tr>
      <td><xsl:value-of select="title" /></td>
      <td><xsl:value-of select="artist" /></td>
    </tr>
    </xsl:for-each>
  </table>
  </body>
  </html>
</xsl:template>

</xsl:stylesheet>

html 文件::

<html>
<head>
<script>
function loadXMLDoc(filename)
{
if (window.ActiveXObject)
  {
  xhttp = new ActiveXObject("Msxml2.XMLHTTP");
  }
else
  {
  xhttp = new XMLHttpRequest();
  }
xhttp.open("GET", filename, false);
try {xhttp.responseType = "msxml-document"} catch(err) {} // Helping IE11
xhttp.send("");
return xhttp.responseXML;
}

function displayResult()
{
xml = loadXMLDoc("cdcatalog.xml");
xsl = loadXMLDoc("cdcatalog.xsl");
// code for IE
if (window.ActiveXObject || xhttp.responseType == "msxml-document")
  {
  ex = xml.transformNode(xsl);
  document.getElementById("example").innerHTML = ex;
  }
// code for Chrome, Firefox, Opera, etc.
else if (document.implementation && document.implementation.createDocument)
  {
  xsltProcessor = new XSLTProcessor();
  xsltProcessor.importStylesheet(xsl);
  resultDocument = xsltProcessor.transformToFragment(xml, document);
  document.getElementById("example").appendChild(resultDocument);
  }
}
</script>
</head>
<body onload="displayResult()">
<div id="example" />
</body>
</html>

知道为什么这些浏览器上会出现这种无意义的错误吗……这个问题也出现在其他浏览器上,这只是我不断测试的一个例子.

any idea why such none sense errors are showing up on these browsers... The issue is also on other browsers and this is just an example where I keep testing..

推荐答案

http://www.w3schools.com/xsl/tryit.asp?filename=cdcatalog 对我来说用 Firefox 和 Opera 很好用,所以你的设置肯定有一些不同.例如,如果 catalog.xsl 文件没有提供正确的 XML MIME 类型,则 XMLHttpRequest 可能不会使用样式表代码填充 responseXML 属性,这可以解释为什么 Firefox 抱怨importStylesheet 调用.

The http://www.w3schools.com/xsl/tryit.asp?filename=cdcatalog works fine for me with Firefox and Opera so there must be some difference in your settings. For instance if the catalog.xsl file is not served with a proper XML MIME type the XMLHttpRequest might not populate the responseXML property with the stylesheet code which could explain why Firefox complains on the importStylesheet call.

这篇关于未捕获的 NotFoundError:无法在“节点"上执行“appendChild":新的子元素为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆