Content related to XML file serialization and deserialization, and content related to xml serialization
Cause:
XML deserialization error. XML document (2, 2) has an error. <configuration xmlns = ''>
Solution:
In fact, this is very simple, because it is generally a problem of incorrect Writing of XML documents!
Just serialize the object you want to deserialize into an XML document. Then compare the XML document with the previous error to know where the error is!
1 private void SerializeObject (string Xmlname) 2 {3 XmlSerializer ser = new XmlSerializer (typeof (Object Type); 4 5 TextWriter writer = new StreamWriter (Xmlname); 6 ser. serialize (writer, object); // object to be serialized 7 writer. close (); 8}View Code
Call the preceding method to serialize an object to an XML document (Xmlname: contains path and Xml file name)
From: http://www.cnblogs.com/louyu/archive/2011/01/06/1929038.html
As soon as I updated it, see the code:
1 /// <summary> 2 /// serialize to XML file 3 /// </summary> 4 /// <typeparam name = "T"> </typeparam> 5 /// <param name = "path"> XML file location </param> 6 private static void SerializeXml <T> (string path) where T: new () 7 {8 T = new t (); 9 var ser = new XmlSerializer (typeof (T); 10 TextWriter writer = new StreamWriter (path ); 11 ser. serialize (writer, t); // the object to be serialized 12 writer. close (); 13}
In-depth questions: