[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

XPath and prefix bindings

  • From: Fraser Goffin <goffinf@gmail.com>
  • To: xml-dev@lists.xml.org
  • Date: Wed, 15 Aug 2012 18:53:55 +0100

XPath and prefix bindings
Here's something I *thought* I understood, but now I'm not so sure ?

Below is an XML instance that includes two namespace prefixes bound to
the same namespace (dis and NS1) :-

<dis:Numbers xmlns:dis="urn:numbers">
	<NS1:Odds xmlns:NS1="urn:numbers">
		<NS1:One>1</NS1:One>
		<NS1:Three>3</NS1:Three>
		<NS1:Five>5</NS1:Five>
	</NS1:Odds>
	<NS1:Evens>
		<NS1:Two>2</NS1:Two>
		<NS1:Four>4</NS1:Four>
		<NS1:Six>6</NS1:Six>
	</NS1:Evens>
</dis:Numbers>

If I use this XPath, I expected it to locate the element 'One' :-

/dis:Numbers/NS1:Odds/NS1:One

however in XMLSpy (I know this has some quirks) I get :-

'Invalid namespace prefix when using XPath 1' (or 'Undefined namespace
prefix 'NS1' if I try using XPath 2)

Hmmmm ..... I *thought* NS1 would be in scope for evaluating the
NS1:Odds location step since it is declared on that node ?

I tried the same thing using various on-line XPath evaluators with
pretty much the same result ?

If however I add the declaration for NS1 to the root element the XPath
locates the node with no problem

<dis:Numbers xmlns:dis="urn:numbers" xmlns:NS1="urn:numbers">
	<NS1:Odds xmlns:NS1="urn:numbers">
		<NS1:One>1</NS1:One>
		<NS1:Three>3</NS1:Three>
		<NS1:Five>5</NS1:Five>
	</NS1:Odds>
	<NS1:Evens>
		<NS1:Two>2</NS1:Two>
		<NS1:Four>4</NS1:Four>
		<NS1:Six>6</NS1:Six>
	</NS1:Evens>
</dis:Numbers>

What am I mis-understanding here ?

Regards

Fraser


[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]


PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.