Altova Mailing List Archives


Re: XPath

From: Serge Baltic <baltic-@-------.--->
To: NULL
Date: 12/11/2007 12:05:00 PM

Hello,

> Consider the following XML
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <Root>
> <Data>
> <ID>1005</ID>
> <Reference>
> <Reference>ABC</Reference>
> <Country>UK</Country>
> </Reference>
> <Reference>
> <Reference>123</Reference>
> <Country>USA</Country>
> </Reference>
> </Data>
> </Root>
> Using XPath, I would like to: Select the value of the Reference Node,
> Where the ID = 1005, And the Country is USA.  The value of the node
> would therefore be 123.
> 
> I'm not great with XPath, but had a go and got it completely wrong:
> XPath = "//Data/[ID ="1005"]/../Reference/[Country="USA"]/Reference"

Should be something like /Root/Data[ID='1005']/Reference[Country='USA']/Reference

Square brackets should apply to the node you're selecting, rather than go 
as an independent path element.

BTW it's a logical error to have an element named “Reference” take part as 
a grouping node at one place and as a value holder in another. That is, the 
semantics should be consistend per element name throughout the document. 
One of them'd better be renamed.

(H) Serge


Disclaimer

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.