//獲取xml數據,並轉換為dataset public static DataSet getConfig(string strXmlPath) { string filePath = GetPhysicalPath(); DataSet ds= ConvertXMLFileToDataSet(GetXmlFullPath(filePath)); return ds; } //將xml文件轉換為DataSet public static DataSet ConvertXMLFileToDataSet(string xmlFile) { StringReader stream = null; XmlTextReader reader = null; try { XmlDocument xmld = new XmlDocument(); xmld.Load(xmlFile); DataSet xmlDS = new DataSet(); stream = new StringReader(xmld.InnerXml); //從stream裝載到XmlTextReader reader = new XmlTextReader(stream); xmlDS.ReadXml(reader); //xmlDS.ReadXml(xmlFile); return xmlDS; } catch (System.Exception ex) { throw ex; } finally { if (reader != null) reader.Close(); } }
本文URL地址:http://www.bianceng.cn/Programming/csharp/201410/45572.htm