This is the test xml that i am using:
<categories>
<category id="1" name="Test1">
<category id="2" name="Test2">
<misc id="1"></misc>
</category>
</category>
<category id="3" name="Test3">
<misc id="2"></misc>
</category>
Now i want to bind that to an ASPX treeview, i want only the elements that have the name category and i want the name of those to appear in the treeview.
Its easy to get the id and names:
var d = from t in data.Descendants("category")
select new { ID = t.Attribute("id").Value, Name = t.Attribute("name").Value };
but how do i keep the structure in the treeview?
This should look like this:
Test1
-> Test2
Test3
Maybe something like this if I understand you correctly? (I have not tested it)
Call it with:
“i want only the elements that have the name category” – I do not understand what you mean here? But if you only want to select those elements which have a “name” attribute then this should work:
I understand that the upper (the “name” attribute part) is not what you wanted but I leave it there. I have tested the code against: