【发布时间】:2014-02-27 19:20:10
【问题描述】:
我正在尝试在 Perl 中使用 XML::XPath 查询 XML 文档,但是当元素的属性名称包含命名空间前缀时,我遇到了问题。
示例 XML:
<root xmlns="root-ns" xmlns:cat="urn:oasis:names:tc:entity:xmlns:xml:catalog" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="A" schematron-version="1.0" xsi:schemaLocation="some location">
<elementA id="elementA">
<ElementA-1>
<ElementA-1-1 id="ElementA-1-1" xlink:href="#ElementA-1-1">
<cat:catalog>
<cat:uri name="name" uri="#something"/>
</cat:catalog>
</ElementA-1-1>
</ElementA-1>
</elementA>
</root>
我的查找查询如下所示:
if ($nodeset = $nodes->find("/root/elementA[\@id='elementA']/ElementA-1/ElementA-1-1[\@xlink:href='#ElementA-1-1']/cat:catalog/cat:uri/\@uri") {
print "nodeset found.\n";
}
else {
print "no nodeset found.\n";
}
当我对示例 XML 文档运行此操作时,XPath 抱怨 @xlink:href 属性名称中的 ':',但我无法在查询中找到引用此属性的正确方法。任何帮助将不胜感激!
【问题讨论】: