阅读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 声明必须是文档中的第一个节点并且在它之前不允许出现空白字符