一个非常方便控制XML的操作类,应用了LINQ 包括XML的读写,节点的读写和添加删除等基本操作。 public class XmlOperator { #region 属性 private string _strPath = ""; /// <summary> /// 文件路径 /// Open时或者Saveas时改变 /// </summary> public string Path { get { return _strPath; } } private XmlDocument _xmlDocumentdoc = null; /// <summary> /// 获取xml对象 /// </summary> public XmlDocument xmlDocument { get { return this._xmlDocumentdoc; } } #endregion public XmlOperator() { } public XmlOperator(string strPath) { _xmlDocumentdoc = OpenXml(strPath); } #region 方法 /// <summary> /// 打开文件 /// </summary> /// <param name="strPath"></param> 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); } /// <summary> /// 将xml对象转化成DataTable /// </summary> /// <returns></returns> 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; }
- operationcwaa2012-12-04不错,不过注释不多,总体错误很少,个别一般都能调试解决。
- manup2012-09-04不错,不过注释不多,总体错误很少,个别一般都能调试解决。
- 粉丝: 1
- 资源: 2
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助