xpath and default namespace

Questions about XML that are not covered by the other forums should go here.
eHannes
Posts: 31
Joined: Sat Apr 16, 2005 11:29 am

xpath and default namespace

Post by eHannes »

Hi,

How can i tell the xpath engine to use the deafult namespace?


When i have the following xml

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<OAI-PMH xmlns="http://www.openarchives.org/OAI/2.0/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/ http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd">
<responseDate>2006-01-23T08:55:15Z</responseDate>
<request verb="ListRecords" metadataPrefix="oai_dc" set="keur" from="2004-06-01"
until="2004-06-30">http://erad.avu.nl/cgi/arno/oai/bupavu</request>
<ListRecords>
<record>
<header>
<identifier>oai:bupavu:120647</identifier>
<datestamp>2004-06-30</datestamp>
<setSpec>keur:yes</setSpec>
<setSpec>keur</setSpec>
</header>
</record>
</ListRecords>
</OAI-PMH>
and i want to find the element setSpec (//setSpec) there are no results.

when i remove the default namespace (xmlns="http://www.openarchives.org/OAI/2.0/") then i do have results.

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<OAI-PMH xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/ http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd">
<responseDate>2006-01-23T08:55:15Z</responseDate>
<request verb="ListRecords" metadataPrefix="oai_dc" set="keur" from="2004-06-01"
until="2004-06-30">http://erad.avu.nl/cgi/arno/oai/bupavu</request>
<ListRecords>
<record>
<header>
<identifier>oai:bupavu:120647</identifier>
<datestamp>2004-06-30</datestamp>
<setSpec>keur:yes</setSpec>
<setSpec>keur</setSpec>
</header>
</record>
</ListRecords>
</OAI-PMH>

How can i tell oxygen to use the default namespace?

Thanks, Hans
george
Site Admin
Posts: 2095
Joined: Thu Jan 09, 2003 2:58 pm

Post by george »

Hello Hans,

XPath 1.0 does not support default namespace in XPath name tests. Therefore everything that does not have a prefix is in no namespace. oXygen maps automatically the prefic "default" to the default namespace so you can use something like //default:setSpec or you can go in the XPath options and define a prefix of your choice mapped to your default namespace and use that when you write the XPath.
XPath 2.0 supports setting a default namespace and oXygen by default sets the default namespace as the default namespace of the root element (you can specify how the automatic association of the default namespace is performed through the XPath options). So if I set the XPath to 2.0 I do not have any problem with //setSpec.

Best Regards,
George
eHannes
Posts: 31
Joined: Sat Apr 16, 2005 11:29 am

Post by eHannes »

Hi George,

Thanks for your reply! but...
oXygen maps automatically the prefic "default" to the default namespace so you can use something like //default:setSpec or you can go in the XPath options and define a prefix of your choice mapped to your default namespace and use that when you write the XPath.
Ok. this works (both default: and the defined one)
XPath 2.0 supports setting a default namespace and oXygen by default sets the default namespace as the default namespace of the root element (you can specify how the automatic association of the default namespace is performed through the XPath options).
Just specifying XPath 2.0 doesn't work for me. It works the same way as with xpath 1.0
Where can I specify the automatic association?


Hans
george
Site Admin
Posts: 2095
Joined: Thu Jan 09, 2003 2:58 pm

Post by george »

Hi Hans,

Next to the XPath entry field there is a synchronized weel button that opend the options exactly to the XPath preferences page. You can go there also with Options->Preferences -- XSLT/FO/XQuery -- XPath. There look for the XPath default namespace section, I have it set as:

Use the namespace of the root only if it is declared as default.

Best Regards,
George
eHannes
Posts: 31
Joined: Sat Apr 16, 2005 11:29 am

Post by eHannes »

You're probably working with 7.0. I'm still running 6.2 :cry:
but thanks for the very complete answers!
george
Site Admin
Posts: 2095
Joined: Thu Jan 09, 2003 2:58 pm

Post by george »

Hello Hans,

Indeed, the handling of XPath default namespace is one on the new additions in v7. In 6.2 the namespaces should work in a similar way for both XPath 1.0 and XPath 2.0, as you noted. The best thing is to set your proxy to namepspace mapping for XPath and always use those prefixes when you want to access something from those namespaces.

Best Regards,
George
Post Reply