An instance of reading data to memory from XML

Source: Internet
Author: User
Tags add date bool string
xml| data

Public Clssimuresultbyonegoods Getonegoodssimulationxml (string pathandfilename)
{
Clssimuresultbyonegoods onegoods = new Clssimuresultbyonegoods ();//A class that you define
Hashtable Alllocationresult = new Hashtable ();
System.Xml.XmlTextReader r = new XmlTextReader (Pathandfilename);
String LocationID = "";
DataTable locationtable = null;
while (R.read ())
{
if (R.nodetype = = XmlNodeType.Element)
{
Switch (r.localname)
{
Case "Result":
Onegoods.goodscode = R.getattribute ("Goodscode");
Onegoods.from = Convert.todatetime (R.getattribute ("FromDate"));
onegoods.to = Convert.todatetime (R.getattribute ("ToDate"));
Break
Case "Location":
LocationID = R.getattribute ("ID");
locationtable = new DataTable ();
LOCATIONTABLE.COLUMNS.ADD ("Date", typeof (DateTime));
LOCATIONTABLE.COLUMNS.ADD ("Safetystock", typeof (decimal));
LOCATIONTABLE.COLUMNS.ADD ("Forecastdemand", typeof (decimal));
LOCATIONTABLE.COLUMNS.ADD ("Finaloutput", typeof (decimal));
LOCATIONTABLE.COLUMNS.ADD ("Finalinput", typeof (decimal));
LOCATIONTABLE.COLUMNS.ADD ("Simustock", typeof (decimal));
LOCATIONTABLE.COLUMNS.ADD ("Simustocktime", typeof (decimal));
LOCATIONTABLE.COLUMNS.ADD ("Importworkday", typeof (BOOL));
LOCATIONTABLE.COLUMNS.ADD ("Importworkday", typeof (BOOL));
Break
Case "Record":
if (locationtable!= null)
{
DataRow dr = Locationtable.newrow ();
dr["Date" = Convert.todatetime (R.getattribute ("date"));
if (R.getattribute ("Safetystock")!= null && r.getattribute ("Safetystock")!= "")
dr["Safetystock"] = Convert.todecimal (R.getattribute ("Safetystock"));
if (R.getattribute ("Forecastdemand")!= null && r.getattribute ("Forecastdemand")!= "")
dr["Forecastdemand"] = Convert.todecimal (R.getattribute ("Forecastdemand"));
if (R.getattribute ("finalinput")!= null && r.getattribute ("Finalinput")!= "")
dr["finalinput"] = Convert.todecimal (R.getattribute ("Finalinput"));
if (R.getattribute ("finaloutput")!= null && r.getattribute ("Finaloutput")!= "")
dr["finaloutput"] = Convert.todecimal (R.getattribute ("Finaloutput"));
if (R.getattribute ("Simustock")!= null && r.getattribute ("Simustock")!= "")
dr["Simustock"] = Convert.todecimal (R.getattribute ("Simustock"));
if (R.getattribute ("simustocktime")!= null && r.getattribute ("Simustocktime")!= "")
dr["simustocktime"] = Convert.todecimal (R.getattribute ("Simustocktime"));
if (R.getattribute ("importworkday")!= null && r.getattribute ("Importworkday")!= "")
dr["Importworkday"] = Convert.toboolean (R.getattribute ("Importworkday"));
if (R.getattribute ("exportworkday")!= null && r.getattribute ("Exportworkday")!= "")
dr["Exportworkday"] = Convert.toboolean (R.getattribute ("Exportworkday"));
LOCATIONTABLE.ROWS.ADD (DR);

}
Break
Default
Break
}
}
else if (R.nodetype = = xmlnodetype.endelement)
{
Switch (r.localname)
{
Case "Location":
if (locationtable!= null)
{
Locationtable.acceptchanges ();
Alllocationresult.add (locationid,locationtable);
LocationID = "";
locationtable = null;
}
Break
Default
Break
}
}
}
Onegoods.alllocationresult = Alllocationresult;
return onegoods;

}



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.