public void SerializeTreeView(TreeView treeView, string fileName)
{
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent =
true;
XmlWriter textWriter = XmlWriter.Create(@"C:\Users\buenb\Documents\projet\EEE.XML", settings);
// Writing the xml declaration tag
textWriter.WriteStartDocument();
// Save the nodes, recursive method
SaveNodes(treeView.Nodes, textWriter);
// End the xml document
textWriter.WriteEndDocument();
textWriter.Close();
}
private void SaveNodes(TreeNodeCollection nodesCollection, XmlWriter textWriter)
for (int i = 0; i < nodesCollection.Count; i++)
TreeNode node = nodesCollection[i];
if (node.Nodes.Count > 0)
textWriter.WriteStartElement(node.Text);
else
textWriter.WriteAttributeString(node.Text,
"Attribute value");
SaveNodes(node.Nodes, textWriter);
textWriter.WriteEndElement();