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