Use XML deserialization to quickly complete ASP. NET configuration files

Source: Internet
Author: User

In general, the configuration file of Asp.net uses Web. config can solve the problem, but sometimes we want to configure something in our own form. For example, we want to configure all the messages of a site in the following form.
<Messages>
<Message id = "id1"> message1 </message>
<Message id = "ID2"> message1 </message>
</Messages>

At this time, the configurationelement does not understand the configuration of message1 in the middle. At this time, we can use XML deserialization to solve this problem.

To use deserialization, we must create a class corresponding to messages. With the help of XML definition tool (xsd.exe), this goal can be easily achieved:
The first step is the XML-> XML Schema (XSD file) command: xsd xml file name. Note that the extension of this XML file name must be. xml.
The second step is the XSD → class command: XSD file name/C. If you want to specify the namespace of the generated class, add/N: mynamespace.

In this way, the class corresponding to the XML is completely generated, and the next step is to read the XML deserialization. In addition, to improve performance, you can use the physical path of the configuration file as the buffer dependency and add the configuration to the cache.

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.