Page 1 of 1

xpath query on xml documents with multiple namespaces

Posted: Wed Dec 19, 2007 10:11 pm
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.

Posted: Thu Dec 20, 2007 12:02 am
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...

Posted: Thu Dec 20, 2007 10:26 pm
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