从XML中读取数据到内存的实例:
public clsSimuResultByOneGoods GetOneGoodsSimulationXML(string PathAndFileName)
{
clsSimuResultByOneGoods OneGoods = new clsSimuResultByOneGoods();//自己定义的一个类
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));