Content related to XML file serialization and deserialization, and content related to xml serialization

Source: Internet
Author: User

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:

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.