XML操作类
using System;
using System.Xml;
using System.Data;
namespace XmlClass
{
/// <summary>
/// XML相关通用功能
/// </summary>
public class XmlHelper
{
public XmlHelper() { }
/// <summary>
/// XML资源类型
/// </summary>
public enum XmlType
{
File,
String
};
#region 读取XML资源到DataSet中
/// <summary>
/// 读取XML资源到DataSet中
/// </summary>
/// <param name="source">XML资源,文件为路径,否则为XML字符串</param>
/// <param name="xmlType">XML资源类型</param>
/// <returns>DataSet</returns>
public static DataSet GetDataSet(string source, XmlType xmlType)
{
DataSet ds = new DataSet();
if (xmlType == XmlType.File)
{
ds.ReadXml(source);
}
else
{
XmlDocument xd = new XmlDocument();
xd.LoadXml(source);
XmlNodeReader xnr = new XmlNodeReader(xd);
ds.ReadXml(xnr);
}
return ds;
}
#endregion
#region 获取一个字符串xml文档中的ds
/// <summary>
/// 获取一个字符串xml文档中的ds
/// </summary>
/// <param name="xml_string">含有xml信息的字符串</param>
public static void get_XmlValue_ds(string xml_string, ref DataSet ds)
{
System.Xml.XmlDocument xd = new XmlDocument();
xd.LoadXml(xml_string);
XmlNodeReader xnr = new XmlNodeReader(xd);
ds.ReadXml(xnr);
xnr.Close();
int a = ds.Tables.Count;
}
#endregion
#region 读取XML资源到DataTable中
/// <summary>
/// 读取XML资源到DataTable中
/// </summary>
/// <param name="source">XML资源,文件为路径,否则为XML字符串</param>
/// <param name="xmlType">XML资源类型:文件,字符串</param>
/// <param name="tableName">表名称</param>
/// <returns>DataTable</returns>
public static DataTable GetTable(string source, XmlType xmlType, string tableName)
{
DataSet ds = new DataSet();
if (xmlType == XmlType.File)
{
ds.ReadXml(source);
}
else
{
XmlDocument xd = new XmlDocument();
&nb
补充:Web开发 , 其他 ,