我在Chrome中打开了一个XML文档,我想测试一些XPath表达式 . XML文档涉及不同的命名空间 . 如何定义前缀URI?
为了测试Chrome中的XPath表达式,我到目前为止使用了 $x("...") .
$x("...")
取自developer.mozilla的Introduction_to_using_XPath_in_JavaScript
实现用户定义的命名空间解析器
function nsResolver(prefix) { var ns = { 'xhtml' : 'http://www.w3.org/1999/xhtml', 'mathml': 'http://www.w3.org/1998/Math/MathML' }; return ns[prefix] || null; }
如果您在XML文档中的任何位置搜索元素“description”,则可以使用local-name()函数 . 例:
$x("//*[local-name()='description']")
在SO上受到this answer的启发 .
2 回答
取自developer.mozilla的Introduction_to_using_XPath_in_JavaScript
实现用户定义的命名空间解析器
如果您在XML文档中的任何位置搜索元素“description”,则可以使用local-name()函数 . 例:
在SO上受到this answer的启发 .