Click here to Skip to main content
15,881,801 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have the following xml tree :

<tree>
 <subtree>
   <leave> green </leave>
   <leave> orange </leave>
   <leave> red </leave>
 </subtree>
</tree>


I need to query to pick the second leave value.

What I have tried:

I'm on a fail with :
dim color = from u in myXMl.<tree>.<subtree>.<leave>.where(function(u) u is u.elementAt(1)) select u.value


1 is for the index, the collection of nodes start at 0,
and the error thrown is "out of range" type

I really don't guess where am I faulty

and
u is u.elementAt(1)
looks too tricky, maybe wrong too

Thanks for suggestions or a new way to solve this
Posted
Updated 21-Aug-22 5:20am

1 solution

<leave>isn't the collection you want to iterate: if you want a leaf in a subtree, you query the subtree which is a collection of leaves. Try something like:
VB
from u in myXML.<tree>.<subtree>.Where(...
 
Share this answer
 
Comments
Member 15627495 21-Aug-22 11:59am    
I update my request by your solution, so I fix the fault.

thank you 'OriginalGriff' !
OriginalGriff 21-Aug-22 12:26pm    
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900