using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;
namespace ConsoleApp2
{
public class Program
{
public static void Main(string[] args)
{
Console.WriteLine(GetDataSetByXml(““”));
}
///
/// 读取xml直接返回DataSet
///
/// Xml的相对路径
/// 已装入XML文档的DataSet
public static DataSet GetDataSetByXml(string strXmlPath)
{
try
{
DataSet ds = new DataSet();
//读取XML到DataSet
ds.ReadXml(GetXmlFullPath(strXmlPath));
if (ds.Tables.Count > 0)
{
return ds;
}
return null;
}
catch (Exception ex)
{
return null;
}
}
private static string GetXmlFullPath(string strPath)
{
//如果路径中含有:符号,则认定为传入的是完整路径
if (strPath.IndexOf(“:”) > 0)
{
return strPath;
}
else
{
//返回完整路径
return System.Web.HttpContext.Current.Server.MapPath(strPath);
}
}
}
}
简单的读取XML文件
最新推荐文章于 2024-04-17 08:54:01 发布