This article describes how to read data from XML to memory instances. For more information, see
Instance for reading data from XML to memory
Public synchronized GetOneGoodsSimulationxml (string PathAndFileName) {jsononegoods = new clsSimuResultByOneGoods (); // A self-defined class 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. localNam E) {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); Loca TionTable. 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 ;}
The above is the content of the instance that reads data from XML to memory. For more information, see PHP Chinese network (www.php1.cn )!