Xml file:
Copy codeThe Code is as follows: <? Xml version = "1.0" encoding = "UTF-8"?> <! -- In addition to this line, all others are manually typed. -->
<CashAcceptType>
<Type>
<Name> normal charges </name>
<Class> CashNormal </class>
<Para> </para>
</Type>
<Type>
<Name> 300 to 100 </name>
<Class> CashReturn </class>
<Parta> 300,100 </para>
</Type>
<Type>
<Name> 50 after 200 </name>
<Class> CashReturn </class>
<Para> 200,50 </para>
</Type>
<Type>
<Name> off </name>
<Class> CashRebate </class>
<Parta> 0.8 </para>
</Type>
<Type>
<Name> discount </name>
<Class> CashRebate </class>
<Parta> 0.7 </para>
</Type>
</CashAcceptType>
Read the. xml file:Copy codeThe Code is as follows: DataSet ds = new DataSet ();
// Read The. xml file to DataSet according to the path
Ds. ReadXml (Application. StartupPath + "\ CashAcceptType. xml ");
// Bind the read record to the drop-down list box
Foreach (DataRowView dr in ds. Tables [0]. DefaultView)
{
CbxType. items. add (dr ["name"]. toString (); // dr ["name. the value of name corresponding to each type in the xml file, that is, normal charges, full 300 minus 100, full 200 minus 50, etc.
}
// Query the related rows of the selected item based on the user's options (that is, find other parameters corresponding to this name based on the given name)
DataRow dr = (DataRow []) ds. tables [0]. select ("name = '" + cbxType. selectedItem. toString () + "'") [0];
Dr ["class"] finds the xml class corresponding to the name
Dr ["para"] Find para