<summary>///Create XML file///</summary>///<param name= "filename" > file name created Called </param>///<param name= "nodename" > Node name collection </param>///<param name= "ValueList" > Properties
Value pairs collection </param> public static void Createxmlfile (String filename,list<string>nodename,hashtable ht) {
XmlDocument document = new XmlDocument (); Create type declaration node XmlNode nodes = document.
Createxmldeclaration ("1.0", "Utf-8", ""); Document.
AppendChild (node); Create root node XmlNode root = document.
CreateElement (Nodename[0]);
XmlNode parentnode = root; Document.
AppendChild (root);
if (Nodename.count > 0) {for (int m = 1; m < nodename.count-1; m++) { XmlNode xnode = document.
CreateNode (XmlNodeType.Element, nodename[m], NULL);
Parentnode.appendchild (XNode); ParentNode = XNode;
}//Set property value foreach (DictionaryEntry de in HT) { XmlNode xnode = document.
CreateNode (XmlNodeType.Element, nodename[nodename.count-1], NULL);
Parentnode.appendchild (XNode); XmlNode attr = document.
CreateNode (Xmlnodetype.attribute, "name", null); attr. Value = de.
Key.tostring ();
XNode.Attributes.SetNamedItem (attr); XmlNode Attr_value = document.
CreateNode (Xmlnodetype.attribute, "value", null); Attr_value. Value = de.
Value.tostring ();
XNode.Attributes.SetNamedItem (Attr_value);
Xnode.attributes. } document.
Save (Application.startuppath + "\" + fileName); }
invocation mode:
list<string> List = new list<string> () & nbsp list.
ADD ("config"); list.
ADD ("Deviconfig"); list.
ADD ("property");
Hashtable ht = new Hashtable (); HT.
ADD ("Device", "SP-3000"); HT.
ADD ("PortName", "COM1"); HT.
ADD ("BaudRate", "19200"); HT.
ADD ("DataBits", "8"); HT.
ADD ("StopBits", "0"); HT.
ADD ("Parity", "0"); HT.
ADD ("Handshake", 1);
Xmlfileutils.createxmlfile ("Config\\imagedevices\\series.xml", List, HT);
Finally, the XML file structure is generated as follows:
<?xml version= "1.0" encoding= "Utf-8"?>
<config>
<deviconfig>
<property name= " Sourceindex "value=" 3 "/>
<property name=" Brightness "value=" 134 "/> <property name=" contrast "
value= "132"/> <property name= "imagetype" value=
"JPG"/> <property "name= imagefun" value= "
page" />
<property name= "ImgWidth" value= "900"/> <property name=
"imghigth" value= "450"/>
<property name= "Toplength" value= "5"/> <property name=
"Leftlength" value= "5"/>
<pro Perty name= "ShortcutKey" value= "5"/>
</deviconfig>
</config>
Note: The above tool class is used only to generate XML files of this type of data structure, for <node>value<node> The XML file for the struct type is not valid (Web search is basically the way to create this type of XML file).