|
xxx
C# - XML To DataSet
by Charles Carroll
Here is the XML Parser:
filename=/experiments/xmltodataset/xmltodataset.aspx
<%@ import namespace = "System.Data"%>
<%@ import namespace = "System.IO"%>
<script language ="c#" runat ="server">
protected void Page_Load(object sender , EventArgs e)
{
FileStream FS=null;
try
{
DataSet ds = new DataSet();
FS=new FileStream(Server.MapPath("/experiments/data/animalslippers.xml"), FileMode.Open);
ds.ReadXml(FS);
string strTableCount=ds.Tables.Count.ToString();
Trace.Write(" number of tables =" + strTableCount);
for(int j=0;j<ds.Tables.Count;j++)
{
Page.Controls.Add(new LiteralControl("<hr><font color='red'>Table #"+ j +" of " + strTableCount + "</font><br>"));
DataGrid d1 = new DataGrid();
d1.ID = "MyDataGrid" +j;
d1.BackColor= System.Drawing.Color.FromName("lightblue");
d1.Width=Unit.Percentage(100);
d1.BorderColor=System.Drawing.Color.FromName("black");
d1.ShowFooter=false;
d1.CellPadding=3;
d1.CellSpacing=0;
d1.Font.Name="Verdana";
d1.Font.Size=new FontUnit(10);
d1.HeaderStyle.BackColor=System.Drawing.ColorTranslator.FromHtml("#aaaadd");
d1.DataSource = new DataView(ds.Tables[j]);
d1.DataBind();
Page.Controls.Add(d1);
}
} // end try
catch(Exception exc1)
{
Trace.Write("blah","blah",exc1);
} // end catch
finally
{
if (FS != null) FS.Close();
} // end finally
} // end page_load
</script>
|