Hi Tom and Rafe,

Here is an example of an XPath statement that returns nodes based on the
values of their siblings (using your XML document). The first will return
one value ('Object1') and the second will return two values ('Object1' and
'Object2'):

Root/Objects/Object/ObjectName[../Methods/MethodName='jim']

Root/Objects/Object/ObjectName[../Methods/MethodName='george']

If you don't want to specify the full hierarchical position of your target
nodes you could use

//ObjectName[../Methods/MethodName='jim']

although this would incur a slight performance hit with large XML documents.

Incidentally, the penultimate line of your XML example should be </Objects>
not <Objects>.

Hope this helps

Tom

-----------------+
tom dyson
t: +44 (0)1608 811870
m: +44 (0)7958 752657
http://torchbox.com

> Below is an xml example.  I need to be able to get a list of ObjectNames
> for a particular MethodName.  So, if my MethodName is george, I should
> have a list of Object1 and Object2 because george is a methodname for
> each object.  I'm having difficulty constructing xpath.  Any help would
> be appreciated.
> 
> <Root>
> <Objects>
> <Object>
> <ObjectName>Object1</ObjectName>
> <Methods>
> <MethodName>jim</MethodName>
> <MethodName>tony</MethodName>
> <MethodName>fred</MethodName>
> <MethodName>george</MethodName>
> <MethodName>jorge</MethodName>
> </Methods>
> </Object>
> <Object>
> <ObjectName>Object2</ObjectName>
> <Methods>
> <MethodName>pete</MethodName>
> <MethodName>craig</MethodName>
> <MethodName>simon</MethodName>
> <MethodName>george</MethodName>
> <MethodName>jorge</MethodName>
> </Methods>
> </Object>
> <Objects>
> </Root>
>
> Thanks - 
> 
> Tom Schreck
> 817-252-4900
> [EMAIL PROTECTED]



-----------------------+
cf-xml mailing list
http://torchbox.com/xml/list.cfm

Reply via email to