Click to See Complete Forum and Search --> : What XPATH expression to use


jerry.gadd
January 17th, 2003, 05:02 AM
I need an XPATH expression to to the following

I have a DOM as below

<Data>
<Object>
<A ExternalId="A"/>
<B ExternalId="B"/>
<A ExternalId="C"/>
<B ExternalId="D"/>
</Objects>
</Data>


I am looking for an XPath expression that will give me the node
<A ExternalId="C"/>

However all I know is that the node is a first level child of "/Data/Objects" and that it has an attribute "ExternalId" with a value of "C"

I tried the following but it doesnt work

oDOM.selectSingleNode("/Data/Objects/.[@ExternalId='C']")

Any ideas

mje
January 17th, 2003, 01:20 PM
You're close, but your xml is invalid to begin with.

<Data>
<Objects>
<A ExternalId="A"/>
<B ExternalId="B"/>
<A ExternalId="C"/>
<B ExternalId="D"/>
</Objects>
</Data>

A valid XPath would be "/Data/Objects/A[@ExternalId='C']"

ShadowGopher
February 6th, 2003, 01:40 PM
You may want to try this nice utility that I came across called XPath Explorer.
XPath Explorer (http://www.purpletech.com/xpe/index.jsp)
It works great for figuring out how to code those complex xpath commands.

Mark