469,626 Members | 1,369 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,626 developers. It's quick & easy.

linq xml nexted node parent

Hi,

i'm using linq to load an xml structure into my classes. the xml consists of
the same node nested for multiple levels e.g.

<node id="node_id01" name="node 01">
<node id="node_id0101" name="node 01 01">
<node id="node_id010101" name="node 01 01 01">
<node id="node_id01010101" name="node 01 01 01 01">
<node id="node_id0101010101" name="node 01 01 01 01 01">
</node>
</node>
</node>
</node>
</node>

The class consits of the properties which map to the xml attributes and has
a children property and a parent property.

Using recursion i am able to constract the class tree from parent to
children, however i'm not able to link up the parent with the child.
the code i'm using is as follows:

private List<NavigationElementGetNodes(XElement xmlelement, bool
enabledOnly, int level )
{
level++;
var elementsQuery = from element in xmlelement.Elements("node")
select new NodeClass{
Id = element.Attribute("id").Value,
Name = element.Attribute("name").Value,
Level = level,
//Parent = parentElement,
Children = GetNodes(element, enabledOnly, level)
};

return elementsQuery.ToList();
}

the parent property is of type NodeClass and i'd like it to be the parent of
the child node or null when level is 0. any subbestments please?
Jan 16 '08 #1
0 2451

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

16 posts views Thread by Joel Byrd | last post: by
4 posts views Thread by Blue Apricot | last post: by
6 posts views Thread by Derek Hart | last post: by
28 posts views Thread by Marc Gravell | last post: by
6 posts views Thread by xla76 | last post: by
3 posts views Thread by =?Utf-8?B?UGF1bCBQcmV3ZXR0?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.