Use C # To write XML configuration files:

Source: Internet
Author: User

Use C # To write XML configuration files:

1. First, you must know the xml format standard. <? Xml version = "1.0" encoding = "GB2312"?> . <? Indicates the start of the instruction. The xml declaration version is 1.0, which is of the encoding type.

2. C # Write the xml configuration file

Use the XmlTextWriter class in the system. xml class library. For example:

XmlTextWriter lXmlWriter = new XmlTextWriter (lFileName, null); ----------------------------------------- create an xml-writing object lXmlWriter
LXmlWriter. Formatting = Formatting. Indented; ----------------------------------------------------- format the start part of the xml file.
LXmlWriter. WriteStartDocument (); ------------------------------------------------------- WriteStartDocument starts to write xml files, which must have
LXmlWriter. WriteStartElement ("BandConfig"); -------------------------------------- the first WriteStartElement (), which is the write Root Node

For (int I = 0; I <mConfigs. Count (); ++ I)
{
// Start Node
LXmlWriter. WriteStartElement ("Band"); -------------------------------------------- write WriteStartElement () again to be the child node of the root node.
LXmlWriter. WriteElementString ("BandWidth", XmlConvert. ToString (mConfigs [I]. BandWidth); element WriteElementString IN THE subnode
LXmlWriter. WriteElementString ("BandColor", (mConfigs [I]. PenColor. ToArgb (). ToString ()));
LXmlWriter. WriteElementString ("BandLine", XmlConvert. ToString (mConfigs [I]. PenWidth ));
// End the node
LXmlWriter. WriteEndElement (); ---------- corresponds to lXmlWriter. WriteStartElement ("Band ., Required
}
LXmlWriter. WriteEndElement (); ------------ corresponds to lXmlWriter. WriteStartElement ("BandConfig"), which must be
LXmlWriter. Close (); ------------------------- corresponds to lXmlWriter. WriteStartDocument () and must have

 

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.