您当前的位置: 首页 >  c#

衣舞晨风

暂无认证

  • 0浏览

    0关注

    1156博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

C# 获取xml数据,并转换为dataset

衣舞晨风 发布时间:2014-01-08 09:46:42 ,浏览量:0

//获取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();
    }
}
关注
打赏
1647422595
查看更多评论
立即登录/注册

微信扫码登录

0.0611s