You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
90 lines
2.1 KiB
90 lines
2.1 KiB
using System;
|
|
using System.IO;
|
|
using System.Xml;
|
|
using System.Data;
|
|
|
|
namespace SiaSun.LMS.Common
|
|
{
|
|
/// <summary>
|
|
/// XmlFiles 的摘要说明。
|
|
/// </summary>
|
|
public class XmlFiles:XmlDocument
|
|
{
|
|
#region 字段与属性
|
|
private string _xmlFileName;
|
|
public string XmlFileName
|
|
{
|
|
set{_xmlFileName = value;}
|
|
get{return _xmlFileName;}
|
|
}
|
|
#endregion
|
|
|
|
#region ------构造函数
|
|
|
|
/// <summary>
|
|
/// 构造函数
|
|
/// </summary>
|
|
public XmlFiles() { }
|
|
|
|
/// <summary>
|
|
/// 构造函数
|
|
/// </summary>
|
|
public XmlFiles(string xmlFile)
|
|
{
|
|
XmlFileName = xmlFile;
|
|
this.Load(xmlFile);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region ------查找节点
|
|
|
|
/// <summary>
|
|
/// 给定一个节点的xPath表达式并返回一个节点
|
|
/// </summary>
|
|
/// <param name="xPath">路径</param>
|
|
/// <returns></returns>
|
|
public XmlNode FindNode(string xPath)
|
|
{
|
|
XmlNode xmlNode = this.SelectSingleNode(xPath);
|
|
return xmlNode;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 给定一个节点的xPath表达式返回其值
|
|
/// </summary>
|
|
/// <param name="xPath">路径</param>
|
|
public string GetNodeValue(string xPath)
|
|
{
|
|
XmlNode xmlNode = this.SelectSingleNode(xPath);
|
|
return xmlNode.InnerText;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 给定一个节点的表达式返回此节点下的孩子节点列表
|
|
/// </summary>
|
|
/// <param name="xPath">路径</param>
|
|
public XmlNodeList GetNodeList(string xPath)
|
|
{
|
|
XmlNodeList nodeList = this.SelectSingleNode(string.Format("descendant::Table[@Name='{0}']", xPath)).ChildNodes;
|
|
return nodeList;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region ------根据XML获得DataTable
|
|
|
|
/// <summary>
|
|
/// 根据XML获得DataTable
|
|
/// </summary>
|
|
public DataTable GetDataTable(string sXml)
|
|
{
|
|
XmlParserContext context = new XmlParserContext(null, null, null, XmlSpace.None);
|
|
XmlTextReader reader = new XmlTextReader(sXml, XmlNodeType.Document, context);
|
|
DataSet ds = new DataSet();
|
|
ds.ReadXml(reader);
|
|
return (ds.Tables.Count > 1) ? ds.Tables[1] : null;
|
|
}
|
|
#endregion
|
|
}
|
|
}
|