如何直接将createNSResolver与lookupNamespaceURI一起使用?
我试图弄清楚 xpath 在 FireFox 中是如何工作的,但我无法解析简单的命名空间前缀。 LookupNamespaceURI 持续返回 null。
我无法在网上找到任何有效的示例,所以我想知道我是否正确使用了这个函数。任何见解都会非常有帮助。
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ev="http://www.w3.org/2001/xml-events">
<head>
<script type="text/javascript">
var testResolver = function()
{
var resolver = document.createNSResolver(document.documentElement);
alert(resolver.lookupNamespaceURI('ev'));
}
</script>
</head>
<body onload="testResolver()">
</body>
</html>
I am trying to use figure out how xpath is working in FireFox, but I am unable to resolve a simple namespace prefix. The lookupNamespaceURI keeps on returning null.
I was unable to find any working examples on the net, so I am wondering if I am using this function correctly. Any insight would be very helpful.
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ev="http://www.w3.org/2001/xml-events">
<head>
<script type="text/javascript">
var testResolver = function()
{
var resolver = document.createNSResolver(document.documentElement);
alert(resolver.lookupNamespaceURI('ev'));
}
</script>
</head>
<body onload="testResolver()">
</body>
</html>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用以下方法为 HTML 文档创建命名空间解析器:
You could use the following method for creating a namespace resolver for HTML document:
确保使用 XML 或 XHTML MIME 类型提供文档,例如
Content-Type: application/xml
或Content-Type: application/xhtml+xml
(示例位于 http://home.arcor.de/martin.honnen/xml/test2011091101.xhtml)。如果您充当 text/html 那么我认为名称空间解析不起作用。Make sure you serve the document with an XML or XHTML MIME type e.g.
Content-Type: application/xml
orContent-Type: application/xhtml+xml
(example at http://home.arcor.de/martin.honnen/xml/test2011091101.xhtml). If you serve as text/html then I don't think namespace resolution will work.