xpath and default namespace
Questions about XML that are not covered by the other forums should go here.
xpath and default namespace
Hi,
How can i tell the xpath engine to use the deafult namespace?
When i have the following xml
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.
How can i tell oxygen to use the default namespace?
Thanks, Hans
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>
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
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
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
Hi George,
Thanks for your reply! but...
Where can I specify the automatic association?
Hans
Thanks for your reply! but...
Ok. this works (both default: and the defined one)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.
Just specifying XPath 2.0 doesn't work for me. It works the same way as with xpath 1.0XPath 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).
Where can I specify the automatic association?
Hans
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
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
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
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
Return to “General XML Questions”
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service