WPF Write Data From a Tree to XML

Hi guys,

So I have the tree-view that I described in a older post.

Now I need to place the tree-view data in XML files with a logical layout.

public class XMLWrite
 {
 // At the moment this will remain standar, so as I can test the code easily.
 static string path = "C:\\Prayance\\file\\prayance.xml";
public static void WriteToXML(TreeModel t)
 {
 try
 {
 StringWriterUtf8 sw = new StringWriterUtf8();
 XmlTextWriter XMLtw = new XmlTextWriter(path, Encoding.UTF8);
XMLtw.Formatting = Formatting.Indented;
 XMLtw.Indentation = 2;
 XMLtw.WriteStartDocument();
 XMLtw.WriteStartElement("Start Element");
 foreach (var i in t.Nodes)
 {
 XMLtw.WriteAttributeString(i.controlType, i.controlValue);
 }
 XMLtw.WriteStartElement("Category 1");
 XMLtw.WriteEndElement();
 XMLtw.WriteStartElement("Category 2");
 XMLtw.WriteEndElement();
 XMLtw.WriteEndElement();
 XMLtw.WriteEndDocument();
 XMLtw.Close();
 }
 catch (Exception exc)
 {
 MessageBox.Show("Something went so wrong !" + exc.Message);
 }
 }
 }
public class StringWriterUtf8 : System.IO.StringWriter
 {
 public override Encoding Encoding
 {
 get { return Encoding.UTF8; }
 }
 }

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *