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.