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