温馨提示:代码在线浏览功能只能做为源码浏览参考,不能展示项目的全部,如果想更进一步了解该代码请下载:Acom进出仓管理系统源码
当前文件路径:AcomStore/Components/XmlControl.cs

1using System; 2
using System.Data; 3
using System.Collections.Generic; 4
using System.Text; 5
using System.Xml; 6
using System.IO; 7
8
//该源码下载自www.51aspx.com(51aspx.com) 9
10
namespace AcomLb.Components 11
{ 12
public class XmlControl 13
{ 14
protected string strXmlFile; 15
protected XmlDocument objXmlDoc = new XmlDocument(); 16
17
public XmlControl(string XmlFile) 18
{ 19
// 20
// TODO: 在这里加入建造函数和程序码 21
// 22
try 23
{ 24
objXmlDoc.Load(XmlFile); 25
} 26
catch (System.Exception ex) 27
{ 28
throw ex; 29
} 30
strXmlFile = XmlFile; 31
} 32
33
public DataView GetData(string XmlPathNode) 34
{ 35
//查找数据,返回一个DataView 36
DataSet ds = new DataSet(); 37
StringReader read = new StringReader(objXmlDoc.SelectSingleNode(XmlPathNode).OuterXml); 38
ds.ReadXml(read); 39
return ds.Tables[0].DefaultView; 40
41
} 42
43
44
public void Replace(string XmlPathNode, string Content) 45
{ 46
//更新节点內容。 47
objXmlDoc.SelectSingleNode(XmlPathNode).InnerText = Content; 48
} 49
50
public void Delete(string Node) 51
{ 52
//刪除一个节点。 53
string mainNode = Node.Substring(0, Node.LastIndexOf("/")); 54
objXmlDoc.SelectSingleNode(mainNode).RemoveChild(objXmlDoc.SelectSingleNode(Node)); 55
} 56
57
public void InsertNode(string MainNode, string ChildNode, string Element, string Content) 58
{ 59
//插入一节点和此节点一个子节点。 60
XmlNode objRootNode = objXmlDoc.SelectSingleNode(MainNode); 61
XmlElement objChildNode = objXmlDoc.CreateElement(ChildNode); 62
objRootNode.AppendChild(objChildNode); 63
XmlElement objElement = objXmlDoc.CreateElement(Element); 64
objElement.InnerText = Content; 65
objChildNode.AppendChild(objElement); 66
} 67
68
public void InsertElement(string MainNode, string Element, string Attrib, string AttribContent, string Content) 69
{ 70
//插入一节点,带一属性。 71
XmlNode objNode = objXmlDoc.SelectSingleNode(MainNode); 72
XmlElement objElement = objXmlDoc.CreateElement(Element); 73
objElement.SetAttribute(Attrib, AttribContent); 74
objElement.InnerText = Content; 75
objNode.AppendChild(objElement); 76
} 77
78
public void InsertElement(string MainNode, string Element, string Content) 79
{ 80
//插入一节点,不带属性。 81
XmlNode objNode = objXmlDoc.SelectSingleNode(MainNode); 82
XmlElement objElement = objXmlDoc.CreateElement(Element); 83
objElement.InnerText = Content; 84
objNode.AppendChild(objElement); 85
} 86
87
public void Save() 88
{ 89
//保存文档。 90
try 91
{ 92
objXmlDoc.Save(strXmlFile); 93
} 94
catch (System.Exception ex) 95
{ 96
throw ex; 97
} 98
objXmlDoc = null; 99
} 100
} 101
} 102





}
}