Code for creating and reading xml files

Source: Internet
Author: User

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

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.