tags:

views:

36

answers:

2

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"&gt;
    <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  A: 

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

Anon
A: 

Here is what worked:

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