LINQ XML控制类

时间:2015-05-29 08:56:08
【文件属性】:
文件名称:LINQ XML控制类
文件大小:19KB
文件格式:CS
更新时间:2015-05-29 08:56:08
XML 操作 LINQ 一个非常方便控制XML的操作类,应用了LINQ 包括XML的读写,节点的读写和添加删除等基本操作。 public class XmlOperator { #region 属性 private string _strPath = ""; /// /// 文件路径 /// Open时或者Saveas时改变 /// public string Path { get { return _strPath; } } private XmlDocument _xmlDocumentdoc = null; /// /// 获取xml对象 /// public XmlDocument xmlDocument { get { return this._xmlDocumentdoc; } } #endregion public XmlOperator() { } public XmlOperator(string strPath) { _xmlDocumentdoc = OpenXml(strPath); } #region 方法 /// /// 打开文件 /// /// public void XmlOpen(string strPath) { XmlDocument xdtdoc = new XmlDocument(); xdtdoc = OpenXml(strPath); if (xdtdoc == null) throw new Exception("打开文件失败,请检查文件路径"); this._xmlDocumentdoc = xdtdoc; } public void XmlSave() { if (this._strPath == "") throw new Exception("文件路径为空或者不存在"); SaveXml(this._xmlDocumentdoc, this._strPath); } public void XmlSaveAs(string strPath) { SaveXml(this._xmlDocumentdoc, strPath); } /// /// 将xml对象转化成DataTable /// /// public DataTable CoverToTable() { if (this._xmlDocumentdoc != null) { DataSet dsxml = null; using (XmlReader reader = new XmlNodeReader(this._xmlDocumentdoc.DocumentElement)) { dsxml = new DataSet(); dsxml.ReadXml(reader); reader.Close(); } if (dsxml != null) return dsxml.Tables[0]; } return null; }

网友评论

  • 不错,不过注释不多,总体错误很少,个别一般都能调试解决。
  • 不错,不过注释不多,总体错误很少,个别一般都能调试解决。