XPath Query (Multiple Parameters)

  • Thread starter Thread starter Ash
  • Start date Start date
A

Ash

Hi,

Using this sample XML ......


<Data>
<House>
<Location> London </Location>
<Type> Detached </Type>
<Value> 200,000 </Value>
</House>
<House>
<Location> London </Location>
<Type> Flat </Type>
<Value> 100,000 </Value>
</House>
</Data>


Is it possible to generate an xpath query which will locate all house nodes
which have a location = "London" and Type = "Flat".

Regards

Ash.
 
Ash said:
<Data>
<House>
<Location> London </Location>
<Type> Detached </Type>
<Value> 200,000 </Value>
</House>
<House>
<Location> London </Location>
<Type> Flat </Type>
<Value> 100,000 </Value>
</House>
</Data>

Is it possible to generate an xpath query which will locate all house
nodes
which have a location = "London" and Type = "Flat".

Untested (!):

"//Data/House[@Location='London' and @Type='Flat']"
 
Hi Ash!

Using this sample XML ......


<Data>
<House>
<Location> London </Location>
<Type> Detached </Type>
<Value> 200,000 </Value>
</House>
<House>
<Location> London </Location>
<Type> Flat </Type>
<Value> 100,000 </Value>
</House>
</Data>


Is it possible to generate an xpath query which will locate all house
nodes
which have a location = "London" and Type = "Flat".

Herfried's solution works for selecting attributes, not the value of
elements.

If you want to select elements (like in your example):

//Data/House/Location [normalize-space(string()) = 'London']/../Type
[normalize-space(string()) = 'Flat']/..

I used normalize-space() to make the XPath-Query work with " London " or
"London".

Cheers

Arne Janning
 
Arne Janning said:
Herfried's solution works for selecting attributes, not the value of
elements.

Ooops... Yes, you are absolutely right... I should definitely take more
sleep...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top