XML base DataSet load XML data file

Source: Internet
Author: User
Tags tostring

When developing a system, it is common to get its description by code, for example, to get an error message from an error number.

These error messages can be stored in an XML data file and read through a DataSet object.

The following functions are read:

public string geterror (int errorid)
{
When you make an error display, you can put the text description of the error number into an XML
File. This is a common way to support multiple languages.
This example extracts the data from an XML file and obtains an error description for the specified ID number.

string filename;
Datarow[] Dr;
The file path can also be configured in the Web. config file
Filename=this. Request.physicalapplicationpath + "/errorinfo.xml";
Create a DataSet object
DataSet ds=new DataSet ("ErrorInfo");
Reading an XML file
Ds. READXML (filename);
To find
Dr=ds. Tables[0]. Select ("code=" + errorid.tostring ());
if (Dr. Length==1)
{
return dr[0]["Description"]. ToString ();
}
Else
{
Return "";
}
}

The following is an example of an XML file:

<errorinfo>
 <erroritem>
  <code>200</code>
   <Description> successful </description>
 </erroritem>
 <erroritem>
   <code>700</code>
  <Description> incorrect password </description>
 </ Erroritem>
 <erroritem>
  <code>800</code>
  < description> account Invalid </description>
 </erroritem>
</errorinfo>

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.