对节点的XPath查询

Edu*_*uro 3 xml xpath libxml2

我应该做错事.在display-name下名为"name"的所有节点的XPath查询是什么?我使用的是libxml2.

<?xml version="1.0" encoding="UTF-8"?>
<description xmlns="http://openoffice.org/extensions/description/2006" xmlns:d="http://openoffice.org/extensions/description/2006"  xmlns:xlink="http://www.w3.org/1999/xlink">
    <version value="2010.05.25" />
    <identifier value="German.frami2006DE.dictionary.from.org.openoffice.de.by.Karl.Zeiler" />
    <display-name>
        <name lang="en">German (DE-frami) spelling, hyphenation, thesaurus</name>
        <name lang="de">Deutsche (DE-frami) Rechtschreibung, Trennung, Thesaurus</name>
    </display-name>
    <platform value="all" />
    <dependencies>
        <OpenOffice.org-minimal-version value="3.0" d:name="OpenOffice.org 3.0" />
    </dependencies>
</description>
Run Code Online (Sandbox Code Playgroud)

Ano*_*non 6

您的文档具有默认命名空间,因此您需要在表达式中注册该命名空间.我从未使用过libxml2,但看看他们的例子,看起来你想要的功能就是xmlXPathRegisterNs

请注意,注册命名空间时,为XPath表达式选择的前缀不必与文档中使用的前缀(如果有)匹配.由于您的文档使用默认命名空间(不是前缀),因此肯定不会.但是,您仍需要在XPath中使用前缀:

/ns:description/ns:display-name/ns:name


Edu*_*uro 5

这是有效的:

xmlXPathRegisterNs(Ctxt, 'ns1', 'http://openoffice.org/extensions/description/2006');
Res := xmlXPathEval('//ns1:name', Ctxt);
Run Code Online (Sandbox Code Playgroud)