title: Export treeview nodes and tags to XML
body: <p>I have a Treeview control in my form and a multiline textbox display. I have a DataTable too, where each datarow contains parameters from an experiment. The nodes are dynamically created and each nodeclick displays the corresponding parameters in the textbox (using the Afterselect event). To connect the nodes and the datarows I added a custom class object as node tags where I store the node name, the node number etc.</p>
  
  <p>I'd like implement the 'Save' function and I'd like to export my treeview node in a separate xml. I can't find a way however, to export the tag object, only text by using this recursive method:</p>
  
  <pre><code>    public class NodeTag
      {
          public string NodeName;
          public string NodeFunc;
          public int NodeNumber;
          public DataRow datarow;
      }
  
      private void btn_save_Click(object sender, EventArgs e)
      {
          xr = new XmlTextWriter("treeview.xml", System.Text.Encoding.UTF8);
          xr.WriteStartDocument();
          //Write our root node
          xr.WriteStartElement(treeView1.Nodes[0].Text);
          foreach (TreeNode node in treeView1.Nodes)
          {
              saveNode2(node.Nodes);
          }
          //Close the root node
          xr.WriteEndElement();
          xr.Close();
      }
  
      private void saveNode2(TreeNodeCollection tnc)
      {
          foreach (TreeNode node in tnc)
          {
              //If we have child nodes, we'll write 
              //a parent node, then iterrate through
              //the children
  
              if (node.Nodes.Count &gt; 0)
              {
                  xr.WriteStartElement(node.Text);
                  saveNode2(node.Nodes);
                  xr.WriteEndElement();
              }
              else //No child nodes, so we just write the text
              {
                  xr.WriteString(node.Text);
  
  
              }
          }
      }
  </code></pre>
  
  <p>I'm not familiar with the XML export so any help would be great.</p>