這篇文章給大家分享的是有關從XML中如何讀取數據到內存的內容。小編覺得挺實用的,因此分享給大家做個參考。一起跟隨小編過來看看吧。
網站建設哪家好,找成都創新互聯公司!專注于網頁設計、網站建設、微信開發、小程序定制開發、集團企業網站建設等服務項目。為回饋新老客戶創新互聯還提供了靜海免費建站歡迎大家使用!從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)); 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; }
感謝各位的閱讀!關于從XML中如何讀取數據到內存就分享到這里了,希望以上內容可以對大家有一定的幫助,讓大家可以學到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到吧!
網站標題:從XML中如何讀取數據到內存-創新互聯
轉載源于:http://vcdvsql.cn/article40/diddho.html
成都網站建設公司_創新互聯,為您提供用戶體驗、App開發、網站策劃、網站內鏈、Google、虛擬主機
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯