Serialization and deserialization of XML

Source: Internet
Author: User

I. Using VS2013 to generate classes

first copy the XML to serialize using Ctr+c (this step must be done)

Second, use VS Generate class

1, first create a new empty class (to set the class name as needed)

2.

3, the class has been built out.

XML serialization of Stasis rice sequence method:

    /// <summary>    ///XML serialization and deserialization/// </summary>     Public Sealed classXmlserializehelper {/// <summary>        ///Deserialization of XML/// </summary>        /// <typeparam name= "T" >entity class</typeparam>        /// <param name= "Xmlorpath" >XML character or XML file path</param>        /// <returns></returns>         Public StaticT xmldeserialize<t> (stringXmlorpath) {            using(FileStream file =NewFileStream (Xmlorpath, FileMode.Open, FileAccess.Read)) {XmlSerializer Serializer=NewXmlSerializer (typeof(T)); T obj=(T) serializer.                Deserialize (file); File.                Close (); returnobj; }        }        /// <summary>        ///Serialization of XML/// </summary>        /// <typeparam name= "T" >entity class</typeparam>        /// <param name= "obj" >entities with Parameters</param>        /// <returns></returns>         Public Static stringXmlserialize<t>(T obj) {using(StringWriter SW =NewStringWriter ()) {XmlSerializer Serializer=NewXmlSerializer (obj.                GetType ()); Serializer.                Serialize (SW, obj); Sw.                Close (); returnSW.            ToString (); }        }    }

Serialization and deserialization of XML

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.