This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: namespace aware java-xpathapi problem
- To: "Sanjay Pandey/Towers Perrin" <pandeys at towers dot com>
- Subject: Re: [xsl] namespace aware java-xpathapi problem
- From: Jeni Tennison <jeni at jenitennison dot com>
- Date: Mon, 12 Nov 2001 17:50:59 +0000
- Cc: xsl-list at lists dot mulberrytech dot com
- Organization: Jeni Tennison Consulting Ltd
- References: <OFB862BB00.AA37A5C8-ON85256B02.005E74A6@towers.com>
- Reply-to: xsl-list at lists dot mulberrytech dot com
Hi Sanjay,
> I have my xml doc like below
>
> <Root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="
> http://www.x.com/XYZ" type="X">
> <level1>
> <level2 xsi:type = 'someValue'>
> <details>description</details>
> </level2>
> </level1>
>
> </Root>
Note that the level2 element (which is in the http://www.x.com/XYZ
namespace) has a type attribute in the
http://www.w3.org/2001/XMLSchema-instance namespace.
> If I try to get to the level2 node by using xpathStr as
> "//xs:level2[@type = 'someValue']", I am unable to get the node. If
> I remove "xsi:" from the XML, then the same XPath works fine.
The path "//xs:level2[@type = 'someValue']" looks for an level2
element in the namespace denoted by the prefix 'xs' that has a type
attribute *in no namespace* with the value 'someValue'. Your XML
document doesn't have such a level2 element - the only level2 element
that it contains has a type attribute *in the
http://www.w3.org/2001/XMLSchema-instance namespace*.
So you need to change the path so that it accesses the value of the
xsi:type attribute instead:
//xs:level2[@xsi:type = 'someValue']
and you need to make sure that your prefix resolver associates the
prefix 'xsi' with the namespace
'http://www.w3.org/2001/XMLSchema-instance'.
I hope that helps,
Jeni
---
Jeni Tennison
http://www.jenitennison.com/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list