XPath query for node

I have to do something wrong. What is an XPath query for all nodes with a name under the display name? I am using 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>
+3
source share
2 answers

Your document has a default namespace, so you need to register that namespace in your expression. I never used libxml2, but looking at their examples , it seems that you need a functionxmlXPathRegisterNs

, , XPath, ( ) . ( ), . XPath:

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

+6

:

xmlXPathRegisterNs(Ctxt, 'ns1', 'http://openoffice.org/extensions/description/2006');
Res := xmlXPathEval('//ns1:name', Ctxt);
+5

Source: https://habr.com/ru/post/1765458/


All Articles