Read XML data to dataset (example: dropdownlist)

Source: Internet
Author: User
Aspx: </ ASP: checkboxlist >
< ASP: dropdownlist ID = "DDL" Runat = "Server" >
</ ASP: dropdownlist >

CS: Dataset DS =   New Dataset ();
String Xmlpath = Server. mappath ( " ~ / " ) +   " Ipusrtest/QQ. xml " ;
DS. readxml (xmlpath );

DDL. datatextfield = " Name " ;
DDL. datavaluefield =   " Value " ;
DDL. datasource = DS;
DDL. databind ();

XML: <? XML version = "1.0" encoding = "UTF-8" ?>  
< Prj >

< Two Value = "1" Name = "Single battery" />
< Two Value = "2" Name = "Combined battery" />
< Two Value = "3" Name = "Charger" />
< Two Value = "4" Name = "Mobile power" />

</ Prj >

Usage class: The method for reading XML data to dataset is:

# Region getdatasetbyxml
/// < Summary >
/// Read XML and return dataset directly
/// </ Summary >
/// < Param Name = "Strxmlpath" > XML file relative path </ Param >
/// < Returns > </ Returns >
Public static dataset getdatasetbyxml (string strxmlpath)
{< br> try
{< br> dataset DS = new dataset ();
// read XML to dataset
DS. readxml (getxmlfullpath (strxmlpath);
If (Ds. tables. count> 0)
{< br> return Ds;
}< br> return NULL;
}< br> catch (exception)
{< br> return NULL;
}< BR ># endregion

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.