views:

90

answers:

2

Consider this xml:

<parent>
    <child name="alpha" />
</parent>

and also this xml

<parent>
    <child name="beta" />
</parent>

There should be only a sinlge node at /parent/child with either alpha or beeta as it's name value.

To clarrify... there will never be 2 child nodes one each named alpha and beta

I'm trying to create a single xpath query which will return the value of name in each of these 2 cases.

I tried this...

/parent/child[@name='alpha' | @name='beta']/@name

...but it does not work.

How should I return this value..?

Update: I ammendedd the samples to ensure they were well formed as one answer indicated they were not.

+7  A: 

Try with:

/parent/child[(@name='alpha') or (@name='beta')]/@name

It should also work without the parentheses.

rslite
Thankyou very much... I'm informed it works perfectly. :)
Rory Becker
+1  A: 

The XML doesn't appear to be well-formed, it should be:

<parent>
    <child name="alpha"/>
</parent>

<parent>
    <child name="beta"/>
</parent>

If the XML isn't well-formed, I wouldn't expect much else to work..

James
Absolutely correct. I have readjusted the original sample to be well formed. The Actual data was well formed however so the problem still remained. However the question is now answered by rslite. Upvoting you anyway because this could well help someone else.
Rory Becker