xml| Program
Simple example of an application, just simple operation of the XML file, in the actual application can first build a configuration class save state.
Structure of the XML file:
1 <?xml version= "1.0" encoding= "Utf-8"?>
2 <config>
3 <function name= "a" checked= "false"/>
4 <function name= "B" checked= "false"/>
5 <function name= "C" checked= "false"/>
6 <function name= "D" checked= "false"/>
7 </config>
Specific program: Need a CheckedListBox, two button
1 public doc as New XmlDocument
2 Public RootNode as XmlElement
3 public strpathconfig as String = Application.startuppath & "\config.xml"
4 Public Intnum as Int16
5 Private Sub Button1_Click () Sub Button1_Click (ByVal sender as System.Object, ByVal e as System.EventArgs) Handles Butt On1. Click
6 Writeconfig ()
7 End Sub
8 Private Sub Form1_Load () Sub Form1_Load (ByVal sender as System.Object, ByVal e as System.EventArgs) Handles Mybase.loa D
9 ' Doing the prep work
Ten Doc. Load (Strpathconfig)
One rootnode = Doc. DocumentElement
Intnum = RootNode. Childnodes.count-1
13 '
Loadconfig ()
End Sub
16 ' Add to CheckedListBox
The function loadconfig () function Loadconfig ()
Dim I as Int16
For i = 0 to Intnum
CHECKEDLISTBOX1.ITEMS.ADD (RootNode. ChildNodes (i). Attributes (0). Value, CType (RootNode. ChildNodes (i). Attributes (1). Value, Boolean))
Next
End Function
23 ' OK, then write XML
function Writeconfig () function Writeconfig ()
Dim I as Int16
Dim Str as String
i = 0 to Intnum
RootNode. ChildNodes (i). Attributes (1). Value = checkedlistbox1.getitemchecked (i). Tostring
Next
Doc. Save (Strpathconfig)
End Function
32
The Private Sub Button2_Click () Sub Button2_Click (ByVal sender as System.Object, ByVal e as System.EventArgs) Handles But Ton2. Click
34 ' need to clear the items in CheckedListBox
CheckedListBox1.Items.Clear ()
Loadconfig ()
Notoginseng End Sub
End---