473,406 Members | 2,698 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,406 software developers and data experts.

Select specific TreeNode to create XmlNode

Hi everyone,

After visiting and using plenty of your solutions exposed in this great website, I've finally got across a problem that I can't find a solution anywhere.

I have a TreeView that is populating a XML file that looks like this:

Expand|Select|Wrap|Line Numbers
  1. <commandset>
  2.   <commandgroup name="Initialization">
  3.     <command name="Reset" id="1">
  4.       ...
  5.     </command>
  6.     <command name="Reset" id="2">
  7.       ...
  8.     </command>
  9.     <command name="Init" id="3">
  10.       ...
  11.     </command>
  12.   </commandgroup>
  13. </commandset>
  14.  
So when I populate the TreeView, I only display the "name" attributes.

My problem starts when I try select one "command" node in the TreeView to extract the data from the XML (and at the end reflect the changes back to the original XML).

To select the XmlNode, I am creating an string with the path to the TreeNode "command" with a function that looks like this:

Expand|Select|Wrap|Line Numbers
  1.  
  2. private string GetTreeNodePathExpresion()
  3.         {
  4.             string expr = null;
  5.             string myNode = treeView1.SelectedNode.Text;
  6.             expr = "/commandset/command [@name='" + myNode + "']";
  7.  
  8.             return expr;    
  9.         }
  10.  
but as you can see in the XML, there are several commands with the same name, and this will always find the first XmlNode that fits the string path pattern.

Is there any way I can identify the TreeNodes using a unique ID or something similar?

Thanks.
Mar 21 '07 #1
5 2180
RedSon
5,000 Expert 4TB
If I could I'd give you an award for best noob first post.
Mar 21 '07 #2
RedSon
5,000 Expert 4TB
Hi everyone,

After visiting and using plenty of your solutions exposed in this great website, I've finally got across a problem that I can't find a solution anywhere.

I have a TreeView that is populating a XML file that looks like this:

Expand|Select|Wrap|Line Numbers
  1. <commandset>
  2.   <commandgroup name="Initialization">
  3.     <command name="Reset" id="1">
  4.       ...
  5.     </command>
  6.     <command name="Reset" id="2">
  7.       ...
  8.     </command>
  9.     <command name="Init" id="3">
  10.       ...
  11.     </command>
  12.   </commandgroup>
  13. </commandset>
  14.  
So when I populate the TreeView, I only display the "name" attributes.

My problem starts when I try select one "command" node in the TreeView to extract the data from the XML (and at the end reflect the changes back to the original XML).

To select the XmlNode, I am creating an string with the path to the TreeNode "command" with a function that looks like this:

Expand|Select|Wrap|Line Numbers
  1.  
  2. private string GetTreeNodePathExpresion()
  3.         {
  4.             string expr = null;
  5.             string myNode = treeView1.SelectedNode.Text;
  6.             expr = "/commandset/command [@name='" + myNode + "']";
  7.  
  8.             return expr;    
  9.         }
  10.  
but as you can see in the XML, there are several commands with the same name, and this will always find the first XmlNode that fits the string path pattern.

Is there any way I can identify the TreeNodes using a unique ID or something similar?

Thanks.
You give them id attributes, can you not use those?
Mar 21 '07 #3
Maybe I didn't explain myself properly, but thanks for the nomination anyway.

I already found a solution:

During the population of the TreeView, when adding a new TreeNode, I am adding the "command" IDs attributes' values to the each "command" by using the Tag property. I've used this:

Expand|Select|Wrap|Line Numbers
  1. treeNode.Tag = xmlNode.Attributes["id"].Value;
So when I select any "command" node from the TreeView, I can check its Tag and chose the appropiate xml node.

There might be other solutions.
Mar 21 '07 #4
RedSon
5,000 Expert 4TB
So your problem is solved then?
Mar 21 '07 #5
Yes, thanks.

So your problem is solved then?
Mar 21 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Michael Bray | last post by:
Is there an easy way to create an XmlNode with a specific XPath, creating nodes along the way if necessary? For example, if I start with an XmlDocument xmlDoc with contents: <Test>...
4
by: mike | last post by:
Hello. Let's say I have the following XML document: <ROOT><Element1>Some Text</Element1></ROOT> I want to add a new element after Element1. I tried the following but, naturally, it doesn't...
4
by: G Uljee | last post by:
How can I find and select an specific item in an treeview control? I want to create a search feature on my treeview. Thanks in advance, Gaby
2
by: Wes | last post by:
I have a treeview that I am continually added nodes to. Each time a new node is added I would like to select that node. Is this possible? I have looked at selectedNode, but I don't know how to...
13
by: André Nogueira | last post by:
Hi there. I know you can view a node's fullpath property, but is it posible to select a node using its path? Like, tell the treeview that the node that should be selected is the node with the...
4
by: Jason Kumpf | last post by:
OK I've been staring at this code all day and still with everything I have tried I cannot figure out two problems I am having. Once is why the space limit for the directory I create in the code...
6
by: DWrek | last post by:
Here is my problem. I have an XML document that is returned to me by a third party service. The XML document contains results for a search but only lists a maximum of 10 results. If there are any...
0
by: divya1949 | last post by:
Create a windows c# application which will Read a xml file and populate nodes in the treeview. 1 On selection of treenode display the child nodes of that node in listview control 2. ...
1
by: jmDesktop | last post by:
I am trying to add nodes with keys to my treeview. I can add general nodes without problem with: //create new node TreeNode newNode = new TreeNode(myIdNumber); //create children TreeNode...
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
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
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.