xpath - is it possible to do this?

Questions about XML that are not covered by the other forums should go here.
fidanken
Posts: 2
Joined: Mon Sep 12, 2005 6:33 pm

xpath - is it possible to do this?

Post by fidanken »

For example in this case:

<bla id = 2>
<A ruolo = 1>
....
</A>
</bla>
<bla id = 10>
<A ruolo = 12>
....
</A>
</bla>

i have to select node whose have attribute ruolo like 1 or 12, i need both nodes. How can i do this?
i made this:
xmlSubTreeNode.SelectNodes("//bla[descendant::*/@Ruolo=1 or /@Ruolo=12]");

But in this case this instruction read only the first condition without read the second (ruolo = 12) if i write AND it try to find a tag with the 2 condition into..and it find nothing..

Does anybody know if i can do this? or is it impossible?
thanks
Fid
george
Site Admin
Posts: 2095
Joined: Thu Jan 09, 2003 2:58 pm

Post by george »

Hi,

Try:
//bla[A/@Ruolo=1 or A/@Ruolo=12]

Regards,
George
fidanken
Posts: 2
Joined: Mon Sep 12, 2005 6:33 pm

Post by fidanken »

i try with your suggest but i receive an xmlnodelist null,
if I insert descendant...so:

//bla[descendant::A/@Ruolo=1 or A/@Ruolo=12]

i find only nodes with Ruolo = 1

Does exist a metod to merge 2 xmlnodelist? so i could make 2 query and merge the result...

Tnks
Fid
george
Site Admin
Posts: 2095
Joined: Thu Jan 09, 2003 2:58 pm

Post by george »

Check the spelling of the elements/attributes, XML is case sensitive.
In your instance you have ruolo and in the XPath there is Ruolo.

For the following XML:

Code: Select all


<test>
<bla id="2">
<A ruolo="1"> .... </A>
</bla>
<bla id="10">
<A ruolo="12"> .... </A>
</bla>
</test>
the following XPath

Code: Select all


//bla[A/@ruolo=1 or A/@ruolo=12] 
gives 2 results:

Code: Select all


SystemID: E:\workspace\oXygen\samples\test.xml
Location: 2:0
Description: /test[1]/bla[1] - id="2"

SystemID: E:\workspace\oXygen\samples\test.xml
Location: 5:0
Description: /test[1]/bla[2] - id="10"
Regards,
George
Post Reply