xpath query on xml documents with multiple namespaces

Having trouble installing Oxygen? Got a bug to report? Post it all here.
bmf1972
Posts: 5
Joined: Mon Jul 19, 2004 8:45 pm

xpath query on xml documents with multiple namespaces

Post by bmf1972 »

using oxygenxml 9.1 on eclipse 3.3

In the xml editor:

Code: Select all

<?xml version="1.0" encoding="utf-8" standalone="no"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Body>
<ConversionRateResponse xmlns="http://www.webserviceX.NET/">
<ConversionRateResult>3.9455</ConversionRateResult>
</ConversionRateResponse>
</soap:Body>
</soap:Envelope>
trying to query with xpath (ctrl-shift-/) :
//ConversionRateResult -- gives "no results"
-- why??

if i would change the xml not to use a prefix for the inner namespace (such as ns0):

Code: Select all

<?xml version="1.0" encoding="utf-8" standalone="no"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Body>
<ns0:ConversionRateResponse xmlns:ns0="http://www.webserviceX.NET/">
<ns0:ConversionRateResult>3.9455</ns0:ConversionRateResult>
</ns0:ConversionRateResponse>
</soap:Body>
</soap:Envelope>
then //ns0:ConversionRateResult
yields: "Invalid XPath expression Prefix must resolve to a namespace: ns0"


Anything that I am doing wrong?

Adrian.
bmf1972
Posts: 5
Joined: Mon Jul 19, 2004 8:45 pm

Post by bmf1972 »

however if i change the xml to look like:

Code: Select all

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ns0="http://www.webserviceX.NET/">
<soap:Body>
<ns0:ConversionRateResponse>
<ns0:ConversionRateResult>3.9455</ns0:ConversionRateResult>
</ns0:ConversionRateResponse>
</soap:Body>
</soap:Envelope>
then it works as expected...
george
Site Admin
Posts: 2095
Joined: Thu Jan 09, 2003 2:58 pm

Post by george »

Hi Adrian,

An XPath expression is executed in a certain namespace context. oXygen computes the namespace context using the namespace declarations from the document root element and the namespace declarations defined in options (Window->Preferences -- oXygen / XML / XSLT-FO-XQuery / XPath -- Default prefix-namespace mappings.

Note also that XPath 1.0 does not have a notion of default namespace, name tests without a prefix are always in no namespace. XPath 2.0 introduced support for default namespace in XPath expressions and oXygen has a few options that allow you to control how that is determined, see the same preferences page Window->Preferences -- oXygen / XML / XSLT-FO-XQuery / XPath, the XPath default namespace section. By default oXygen will add as default namespace the namespace of the root element only if that is declared as default namespace.

I hope the above explains all the cases you encountered. If you think you need more details about one of them, or about some other case just let me know.

Best Regards,
George
George Cristian Bina
Post Reply