[Home] [By Thread] [By Date] [Recent Entries]

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

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]


Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member