473,405 Members | 2,176 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

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 2567

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Piet | last post by:
Hi there, I have managed to write a small java program that display an xml file in a JTree. This was achieved by defining a suitable tree model. THe program works...somehow. The nodes (elements...
16
by: Joel Byrd | last post by:
I am having this ridiculous problem of trying to set the innerHTML of a div node. It works in all other browsers, but internet explorer is giving me an "Unknown runtime error". This is actually...
4
by: Blue Apricot | last post by:
How can I prevent certain Class properties from cascading from a parent table to its children? Specifically, I have a table that acts as a container (I call it class="page"), with a certain...
6
by: Derek Hart | last post by:
I bring in an xml file into vb.net by using xmlDoc.LoadXml(XMLString) - I run xpath statements against the xml file to grab data from it, so I use, as an example, //Vehicles/Vehicles/@make to get...
28
by: Marc Gravell | last post by:
In Linq, you can apparently get a meaningful body from and expression's .ToString(); random question - does anybody know if linq also includes a parser? It just seemed it might be a handy way to...
6
by: xla76 | last post by:
I have a simple treeview (treeview1) to which I have added two nodes (nodeA and nodeB) which have n levels of child nodes. What I want is to be able to identify whether the child node I select...
6
by: Iaml | last post by:
I have an XML file and the depth of each node is unpredictable. I need to find the parent node which contains an element whose certain attribute has the given value. Then I will process that...
3
by: =?Utf-8?B?UGF1bCBQcmV3ZXR0?= | last post by:
I'm attempting to use LINQ to insert a record into a child table and I'm receiving a "Specified cast is not valid" error that has something to do w/ the keys involved. The stack trace is: ...
1
by: SWETA123 | last post by:
I will very helpful to you if you can help me out in my below problem. I am not getting idea what should be the right approach for this. Here is my problem. I have below (sample)xml. <Rules>...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.