从XML中读取数据到内存的实例

 

None.gif public  clsSimuResultByOneGoods GetOneGoodsSimulationXML( string  PathAndFileName)
ExpandedBlockStart.gifContractedBlock.gif        
dot.gif {
InBlock.gif            clsSimuResultByOneGoods OneGoods 
= new clsSimuResultByOneGoods();//自己定义的一个类
InBlock.gif
            Hashtable AllLocationResult = new Hashtable();
InBlock.gif            System.Xml.XmlTextReader r 
= new XmlTextReader(PathAndFileName);
InBlock.gif            
string LocationID = "";
InBlock.gif            DataTable LocationTable 
= null;
InBlock.gif            
while(r.Read())
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if(r.NodeType == XmlNodeType.Element)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
switch(r.LocalName)
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        
case "Result":
InBlock.gif                            OneGoods.GoodsCode 
= r.GetAttribute("GoodsCode");
InBlock.gif                            OneGoods.From 
= Convert.ToDateTime(r.GetAttribute("FromDate"));
InBlock.gif                            OneGoods.To 
= Convert.ToDateTime(r.GetAttribute("ToDate"));
InBlock.gif                            
break;
InBlock.gif                        
case "Location":
InBlock.gif                            LocationID 
= r.GetAttribute("ID");
InBlock.gif                            LocationTable 
= new DataTable();
InBlock.gif                            LocationTable.Columns.Add(
"Date",typeof(DateTime));
InBlock.gif                            LocationTable.Columns.Add(
"SafetyStock",typeof(decimal));
InBlock.gif                            LocationTable.Columns.Add(
"ForecastDemand",typeof(decimal));
InBlock.gif                            LocationTable.Columns.Add(
"FinalOutput",typeof(decimal));
InBlock.gif                            LocationTable.Columns.Add(
"FinalInput",typeof(decimal));
InBlock.gif                            LocationTable.Columns.Add(
"SimuStock",typeof(decimal));
InBlock.gif                            LocationTable.Columns.Add(
"SimuStockTime",typeof(decimal));
InBlock.gif                            LocationTable.Columns.Add(
"ImportWorkDay",typeof(bool));
InBlock.gif                            LocationTable.Columns.Add(
"ImportWorkDay",typeof(bool));
InBlock.gif                            
break;
InBlock.gif                        
case "Record":
InBlock.gif                            
if(LocationTable != null)
ExpandedSubBlockStart.gifContractedSubBlock.gif                            
dot.gif{
InBlock.gif                                DataRow dr 
= LocationTable.NewRow();
InBlock.gif                                dr[
"Date"= Convert.ToDateTime(r.GetAttribute("Date"));
InBlock.gif                                
if(r.GetAttribute("SafetyStock"!= null && r.GetAttribute("SafetyStock"!= "")
InBlock.gif                                    dr[
"SafetyStock"= Convert.ToDecimal(r.GetAttribute("SafetyStock"));
InBlock.gif                                
if(r.GetAttribute("ForecastDemand"!= null && r.GetAttribute("ForecastDemand"!= "")
InBlock.gif                                    dr[
"ForecastDemand"= Convert.ToDecimal(r.GetAttribute("ForecastDemand"));
InBlock.gif                                
if(r.GetAttribute("FinalInput"!= null && r.GetAttribute("FinalInput"!= "")
InBlock.gif                                    dr[
"FinalInput"= Convert.ToDecimal(r.GetAttribute("FinalInput"));
InBlock.gif                                
if(r.GetAttribute("FinalOutput"!= null && r.GetAttribute("FinalOutput"!= "")
InBlock.gif                                    dr[
"FinalOutput"= Convert.ToDecimal(r.GetAttribute("FinalOutput"));
InBlock.gif                                
if(r.GetAttribute("SimuStock"!= null && r.GetAttribute("SimuStock"!= "")
InBlock.gif                                    dr[
"SimuStock"= Convert.ToDecimal(r.GetAttribute("SimuStock"));
InBlock.gif                                
if(r.GetAttribute("SimuStockTime"!= null && r.GetAttribute("SimuStockTime"!= "")
InBlock.gif                                    dr[
"SimuStockTime"= Convert.ToDecimal(r.GetAttribute("SimuStockTime"));
InBlock.gif                                
if(r.GetAttribute("ImportWorkDay"!= null && r.GetAttribute("ImportWorkDay"!= "")
InBlock.gif                                    dr[
"ImportWorkDay"= Convert.ToBoolean(r.GetAttribute("ImportWorkDay"));
InBlock.gif                                
if(r.GetAttribute("ExportWorkDay"!= null && r.GetAttribute("ExportWorkDay"!= "")
InBlock.gif                                    dr[
"ExportWorkDay"= Convert.ToBoolean(r.GetAttribute("ExportWorkDay"));
InBlock.gif                                LocationTable.Rows.Add(dr);
InBlock.gif
ExpandedSubBlockEnd.gif                            }

InBlock.gif                            
break;
InBlock.gif                        
default:
InBlock.gif                            
break;
ExpandedSubBlockEnd.gif                    }

ExpandedSubBlockEnd.gif                }

InBlock.gif                
else if(r.NodeType == XmlNodeType.EndElement)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
switch(r.LocalName)
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        
case "Location":
InBlock.gif                            
if(LocationTable != null)
ExpandedSubBlockStart.gifContractedSubBlock.gif                            
dot.gif{
InBlock.gif                                LocationTable.AcceptChanges();
InBlock.gif                                AllLocationResult.Add(LocationID,LocationTable);
InBlock.gif                                LocationID 
= "";
InBlock.gif                                LocationTable 
= null;
ExpandedSubBlockEnd.gif                            }

InBlock.gif                            
break;
InBlock.gif                        
default:
InBlock.gif                            
break;
ExpandedSubBlockEnd.gif                    }

ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif            OneGoods.AllLocationResult 
= AllLocationResult;
InBlock.gif            
return OneGoods;
InBlock.gif            
ExpandedBlockEnd.gif        }

None.gif

转载于:https://www.cnblogs.com/yangyang8848/archive/2006/04/18/378004.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值