XML操作公共类
来源:互联网 发布:温岭法院淘宝拍卖网 编辑:程序博客网 时间:2024/04/29 19:41
using System;
using System.IO;
using System.Data;
using System.Xml;
using System.Xml.XPath;
namespace ExecuteXml
...{
public class XmlControl
...{
protected string strXmlFile;
protected XmlDocument objXmlDoc = new XmlDocument();
public XmlControl(string XmlFile)
...{
try
...{
objXmlDoc.Load(XmlFile);
}
catch (System.Exception ex)
...{
throw ex;
}
strXmlFile = XmlFile;
}
public DataView GetData(string XmlPathNode)
...{
DataSet ds = new DataSet();
StringReader read = new StringReader(objXmlDoc.SelectSingleNode(XmlPathNode).OuterXml);
ds.ReadXml(read);
return ds.Tables[0].DefaultView;
}
public void Replace(string XmlPathNode,string Content)
...{
objXmlDoc.SelectSingleNode(XmlPathNode).InnerText = Content;
}
public void Delete(string Node)
...{
string mainNode = Node.Substring(0,Node.LastIndexOf("/"));
objXmlDoc.SelectSingleNode(mainNode).RemoveChild(objXmlDoc.SelectSingleNode(Node));
}
public void InsertNode(string MainNode,string ChildNode,string Element,string Content)
...{
XmlNode objRootNode = objXmlDoc.SelectSingleNode(MainNode);
XmlElement objChildNode = objXmlDoc.CreateElement(ChildNode);
objRootNode.AppendChild(objChildNode);
XmlElement objElement = objXmlDoc.CreateElement(Element);
objElement.InnerText = Content;
objChildNode.AppendChild(objElement);
}
public void InsertElement(string MainNode,string Element,string Attrib,string AttribContent,string Content)
...{
XmlNode objNode = objXmlDoc.SelectSingleNode(MainNode);
XmlElement objElement = objXmlDoc.CreateElement(Element);
objElement.SetAttribute(Attrib,AttribContent);
objElement.InnerText = Content;
objNode.AppendChild(objElement);
}
public void InsertElement(string MainNode,string Element,string Content)
...{
XmlNode objNode = objXmlDoc.SelectSingleNode(MainNode);
XmlElement objElement = objXmlDoc.CreateElement(Element);
objElement.InnerText = Content;
objNode.AppendChild(objElement);
}
public void Save()
...{
try
...{
objXmlDoc.Save(strXmlFile);
}
catch (System.Exception ex)
...{
throw ex;
}
objXmlDoc = null;
}
}
}
using System.IO;
using System.Data;
using System.Xml;
using System.Xml.XPath;
namespace ExecuteXml
...{
public class XmlControl
...{
protected string strXmlFile;
protected XmlDocument objXmlDoc = new XmlDocument();
public XmlControl(string XmlFile)
...{
try
...{
objXmlDoc.Load(XmlFile);
}
catch (System.Exception ex)
...{
throw ex;
}
strXmlFile = XmlFile;
}
public DataView GetData(string XmlPathNode)
...{
DataSet ds = new DataSet();
StringReader read = new StringReader(objXmlDoc.SelectSingleNode(XmlPathNode).OuterXml);
ds.ReadXml(read);
return ds.Tables[0].DefaultView;
}
public void Replace(string XmlPathNode,string Content)
...{
objXmlDoc.SelectSingleNode(XmlPathNode).InnerText = Content;
}
public void Delete(string Node)
...{
string mainNode = Node.Substring(0,Node.LastIndexOf("/"));
objXmlDoc.SelectSingleNode(mainNode).RemoveChild(objXmlDoc.SelectSingleNode(Node));
}
public void InsertNode(string MainNode,string ChildNode,string Element,string Content)
...{
XmlNode objRootNode = objXmlDoc.SelectSingleNode(MainNode);
XmlElement objChildNode = objXmlDoc.CreateElement(ChildNode);
objRootNode.AppendChild(objChildNode);
XmlElement objElement = objXmlDoc.CreateElement(Element);
objElement.InnerText = Content;
objChildNode.AppendChild(objElement);
}
public void InsertElement(string MainNode,string Element,string Attrib,string AttribContent,string Content)
...{
XmlNode objNode = objXmlDoc.SelectSingleNode(MainNode);
XmlElement objElement = objXmlDoc.CreateElement(Element);
objElement.SetAttribute(Attrib,AttribContent);
objElement.InnerText = Content;
objNode.AppendChild(objElement);
}
public void InsertElement(string MainNode,string Element,string Content)
...{
XmlNode objNode = objXmlDoc.SelectSingleNode(MainNode);
XmlElement objElement = objXmlDoc.CreateElement(Element);
objElement.InnerText = Content;
objNode.AppendChild(objElement);
}
public void Save()
...{
try
...{
objXmlDoc.Save(strXmlFile);
}
catch (System.Exception ex)
...{
throw ex;
}
objXmlDoc = null;
}
}
}
- 操作XML公共类
- 操作XML公共类 .
- XML操作公共类
- 字节公共操作类
- 日期操作公共类
- JDBC公共操作类
- SQLite操作公共类
- java数据库操作公共类
- Java线程操作公共类
- 公共的Json操作类
- jdbc操作数据库公共类
- PHP操作MySQL公共类
- Cookie操作公共方法类
- C#类实现字符串的公共操作
- C# 操作Access的公共类
- 操作ini文件的公共类
- java中操作JSON公共类
- C#类实现字符串的公共操作
- MySQL中的datetime与timestamp比较
- Matrix 移动的使用
- 设计模式——适配器模式
- *PyQt4 精彩实例分析* 实例17 综合布局实例
- biee11g 提示空值如何去掉
- XML操作公共类
- 计算字符串距离
- Eclipse环境优化策略—配置参数
- MySQL数据库
- halcon例程学习笔记(5)----halcon中如何自己创建子过程
- opendaylight笔记3.opendaylight
- 棋局之谜
- SQL联合查询中的关键语法
- 设置控件全局显示样式appearance proxy