閱讀400 返回首頁    go 阿裏雲 go 技術社區[雲棲]


C# 獲取xml數據,並轉換為dataset

//獲取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();
    }
}

最後更新:2017-04-03 12:54:18

  上一篇:go PPT一打開就放映,怎麼樣能還原到可以更改的窗口呢?
  下一篇:go XML 聲明必須是文檔中的第一個節點並且在它之前不允許出現空白字符