XPath error with namespaces
Oxygen general issues.
-
- Posts: 1
- Joined: Tue Mar 02, 2010 8:12 pm
XPath error with namespaces
Post by clintbergman »
Given the following XML that validates as well formed:
Using 'Xpath 2.0' in Oxygen 11.1 I get the following results:
Query: /GPO/Computer/ExtensionData/Extension/*
Result: /GPO[1]/Computer[1]/ExtensionData[1]/Extension[1]/q2:MsiApplication[1]
Query: /GPO/Computer/ExtensionData/Extension/namespace::*[name() = 'q2']
Result: q2 - http://www.microsoft.com/GroupPolicy/Se ... stallation
Query: /GPO/Computer/ExtensionData/Extension/q2:MsiApplication
Error: XPath failed ... Prefix q2 has not been declared
The error doesn't seem right to me, is this a bug, or am I doing something wrong?
Code: Select all
<?xml version="1.0" encoding="utf-16"?>
<GPO xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.microsoft.com/GroupPolicy/Settings">
<Computer>
<VersionDirectory>35</VersionDirectory>
<VersionSysvol>35</VersionSysvol>
<Enabled>true</Enabled>
<ExtensionData>
<Extension xmlns:q2="http://www.microsoft.com/GroupPolicy/Settings/SoftwareInstallation" xsi:type="q2:SoftwareInstallationSettings">
<q2:MsiApplication>
</q2:MsiApplication>
</Extension>
</ExtensionData>
</Computer>
</GPO>
Query: /GPO/Computer/ExtensionData/Extension/*
Result: /GPO[1]/Computer[1]/ExtensionData[1]/Extension[1]/q2:MsiApplication[1]
Query: /GPO/Computer/ExtensionData/Extension/namespace::*[name() = 'q2']
Result: q2 - http://www.microsoft.com/GroupPolicy/Se ... stallation
Query: /GPO/Computer/ExtensionData/Extension/q2:MsiApplication
Error: XPath failed ... Prefix q2 has not been declared
The error doesn't seem right to me, is this a bug, or am I doing something wrong?
-
- Posts: 2879
- Joined: Tue May 17, 2005 4:01 pm
Re: XPath error with namespaces
Hi,
You have to specify the namespace, not the prefix. For example:
or
If you activate XPath update on caret move(to the right of the XPath combo) and move the caret to q2:MsiApplication you will see in the XPath combo the second variant I've shown you above.
For XPath 2.0 you can also declare default prefix-namespace mappings in Options -> Preferences -> XML -> XSLT-FO-XQuery -> XPath.
So if you declare that q2 is mapped to http://www.microsoft.com/GroupPolicy/Se ... stallation then you can use your original query:
After declaring the prefix-namespace mapping the 'XPath update on caret move' will also change its XPath to the same original query when the caret is in q2:MsiApplication.
Let me know if you have further questions.
Regards,
Adrian
You have to specify the namespace, not the prefix. For example:
Code: Select all
/GPO/Computer/ExtensionData/Extension/*:MsiApplication[namespace-uri()='http://www.microsoft.com/GroupPolicy/Settings/SoftwareInstallation']
Code: Select all
/GPO/Computer/ExtensionData/Extension/*[namespace-uri()='http://www.microsoft.com/GroupPolicy/Settings/SoftwareInstallation' and local-name()='MsiApplication']
For XPath 2.0 you can also declare default prefix-namespace mappings in Options -> Preferences -> XML -> XSLT-FO-XQuery -> XPath.
So if you declare that q2 is mapped to http://www.microsoft.com/GroupPolicy/Se ... stallation then you can use your original query:
Code: Select all
/GPO/Computer/ExtensionData/Extension/q2:MsiApplication
Let me know if you have further questions.
Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ Artificial Intelligence (AI Positron Assistant add-on)
- ↳ 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