3

I should be doing something wrong. What is the XPath query for all nodes named "name" under 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>

2 Answers 2

6

Your document has a default namespace, so you need to register that namespace in your expression. I've never used libxml2, but looking at their examples, it would appear that the function you want is xmlXPathRegisterNs

Note that when you register a namespace, the prefix that you choose for your XPath expression doesn't have to match the prefix (if any) used in the document. Since you're document uses a default namespace (not prefix), it definitely won't. However, you still need to use a prefix in your XPath:

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

Sign up to request clarification or add additional context in comments.

Comments

5

Here is what worked:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.