asp.net to set the XML file as a data source instance (1/2)

Source: Internet
Author: User

ASP tutorial. NET to set an XML file as a data source instance
<%@ Page language= "C #" contenttype= "text/html" responseencoding= "gb2312"%>
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/>
<title></title>
<body>
<%

asp.net tutorial setting an XML file as a data source instance
<summary>
Reads the XML file information and converts it to a DataSet object
</summary>
<remarks>
DataSet ds = new DataSet ();
ds = Cxmlfiletodataset ("/xml/upload.xml");
</remarks>
<param name= "Xmlfilepath" >xml file address </param>
<returns>dataset Objects </returns>
public static DataSet Cxmlfiletodataset (String xmlfilepath)
{
if (!string. IsNullOrEmpty (Xmlfilepath))
{
String path =system.windows.forms.application.startuppath + system.configuration.configurationmanager.appsettings["Flow"]+ Xmlfilepath;

string path = Xmlfilepath;

StringReader strstream = null;

XmlTextReader xmlrdr = null;

Try
{
XmlDocument xmldoc = new XmlDocument (); Load an XML file from an address

XmlDoc. Load (path);

DataSet ds = new DataSet (); Reading character streams in files

Strstream = new StringReader (xmldoc. INNERXML); Get the data in the Strstream

Xmlrdr = new XmlTextReader (Strstream); DS Gets the data in Xmlrdr

Ds. READXML (XMLRDR);

return DS;
}
catch (Exception e)
{
Throw e;
}
Finally
{
Releasing resources
if (xmlrdr!= null)
{
Xmlrdr.close ();

Strstream.close ();

Strstream.dispose ();
}
}
}
Else
{
return null;
}
}
%>

asp.net read XML instance

Home 1 2 last page

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.