1using System;
2using System.Xml;
3using System.Web;
4namespace solucky
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
5
{
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
6 /**//**//**//// <summary>
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
7 /**//// 必需用XPATH表达式来获取相应节点
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
8 /**//// 关于xpath可以参见:
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
9 /**//// </summary>
10 public class MyXml
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
11
{
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
12 变量变量#region 变量
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
13 /**//**//**//// <summary>
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
14 /**//// xml文件所在路径类型
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
15 /**//// </summary>
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
16 /**//// <remarks>xml文件所在路径类型</remarks>
17 public enum enumXmlPathType
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
18
{
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
19 /**//**//**//// <summary>
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
20 /**//// 绝对路径
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
21 /**//// </summary>
22 AbsolutePath,
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
23 /**//**//**//// <summary>
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
24 /**//// 虚拟路径
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
25 /**//// </summary>
26 VirtualPath
27 }
28
29 private string xmlFilePath ;
30 private enumXmlPathType xmlFilePathType ;
31 private XmlDocument xmlDoc = new XmlDocument() ;
32 #endregion
33
34
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
35 属性属性#region 属性
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
36 /**//**//**//// <summary>
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
37 /**//// 文件路径
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
38 /**//// </summary>
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
39 /**//// <remarks>文件路径</remarks>
40 public string XmlFilePath
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
41
{
42 get
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
43
{
44 return this.xmlFilePath;
45 }
46 set
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
47
{
48 xmlFilePath = value ;
49
50 }
51 }
52
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
53 /**//**//**//// <summary>
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
54 /**//// 文件路径类型
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
55 /**//// </summary>
56 public enumXmlPathType XmlFilePathTyp
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
57
{
58 set
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
59
{
60 xmlFilePathType = value ;
61 }
62 }
63 #endregion
64
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
65 构造函数构造函数#region 构造函数
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
66 /**//**//**//// <summary>
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
67 /**////
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
68 /**//// </summary>
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
69 /**//// <param name="tempXmlFilePath"></param>
70 public MyXml( string tempXmlFilePath )
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
71
{
72 //
73 // TODO: 在此处添加构造函数逻辑
74 //
75
76 this.xmlFilePathType = enumXmlPathType.VirtualPath ;
77 this.xmlFilePath = tempXmlFilePath ;
78 GetXmlDocument() ;
79 //xmlDoc.Load( xmlFilePath ) ;
80 }
81
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
82 /**//**//**//// <summary>
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
83 /**//// 构造函数
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
84 /**//// </summary>
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
85 /**//// <param name="tempXmlFilePath">文件路径</param>
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
86 /**//// <param name="tempXmlFilePathType">类型</param>
87 public MyXml( string tempXmlFilePath , enumXmlPathType tempXmlFilePathType )
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
88
{
89 //
90 // TODO: 在此处添加构造函数逻辑
91 //
92 this.xmlFilePathType = tempXmlFilePathType ;
93 this.xmlFilePath = tempXmlFilePath ;
94 GetXmlDocument() ;
95 }
96 #endregion
97
98
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
99 /**//**//**////<summary>
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
100 /**////获取XmlDocument实体类
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
101 /**////</summary>
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
102 /**//// <returns>指定的XML描述文件的一个xmldocument实例</returns>
103 private XmlDocument GetXmlDocument()
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
104
{
105 XmlDocument doc=null;
106
107 if( this.xmlFilePathType == enumXmlPathType.AbsolutePath )
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
108
{
109 doc = GetXmlDocumentFromFile( xmlFilePath ) ;
110 }
111 else if( this.xmlFilePathType == enumXmlPathType.VirtualPath )
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
112
{
113 doc = GetXmlDocumentFromFile(HttpContext.Current.Server.MapPath(xmlFilePath)) ;
114 }
115 return doc;
116 }
117
118 private XmlDocument GetXmlDocumentFromFile(string tempXmlFilePath)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
119
{
120 string xmlFileFullPath = tempXmlFilePath ;
121 xmlDoc.Load(xmlFileFullPath) ;
122 //定义事件处理
123 xmlDoc.NodeChanged += new XmlNodeChangedEventHandler(this.nodeUpdateEvent);
124 xmlDoc.NodeInserted += new XmlNodeChangedEventHandler(this.nodeInsertEvent);
125 xmlDoc.NodeRemoved += new XmlNodeChangedEventHandler(this.nodeDeleteEvent);
126 return xmlDoc ;
127 }
128
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
129 读取指定节点的指定属性值读取指定节点的指定属性值#region 读取指定节点的指定属性值
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
130 /**//**//**//// <summary>
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
131 /**//// 功能:
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
132 /**//// 读取指定节点的指定属性值
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
133 /**//// </summary>
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
134 /**//// <param name="strNode">节点名称</param>
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
135 /**//// <param name="strAttribute">此节点的属性</param>
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
136 /**//// <returns></returns>
137 public string GetXmlNodeAttributeValue(string strNode,string strAttribute)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
138
{
139 string strReturn = "";
140 try
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
141
{
142 //根据指定路径获取节点
143 XmlNode xmlNode = xmlDoc.SelectSingleNode(strNode) ;
144 if (!(xmlNode==null))
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
145
{//获取节点的属性,并循环取出需要的属性值
146 XmlAttributeCollection xmlAttr = xmlNode.Attributes ;
147
148 for(int i=0 ;i<xmlAttr.Count; i++)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
149
{
150 if (xmlAttr.Item(i).Name == strAttribute)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
151
{
152 strReturn = xmlAttr.Item(i).Value ;
153 break;
154 }
155 }
156 }
157 }
158 catch(XmlException xmle)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
159
{
160 throw xmle ;
161 }
162 return strReturn ;
163 }
164 #endregion
165
166
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
167 读取指定节点的值读取指定节点的值#region 读取指定节点的值
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
168 /**//**//**//// <summary>
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
169 /**//// 功能:
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
170 /**//// 读取指定节点的值
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
171 /**//// </summary>
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
172 /**//// <param name="strNode">节点名称</param>
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
173 /**//// <returns></returns>
174 public string GetXmlNodeValue(string strNode)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
175
{
176 string strReturn = String.Empty ;
177
178 try
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
179
{
180 //根据路径获取节点
181 XmlNode xmlNode = xmlDoc.SelectSingleNode(strNode) ;
182 if (!(xmlNode==null))
183 strReturn = xmlNode.InnerText ;
184 }
185 catch(XmlException xmle)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
186
{
187 throw xmle ;
188 }
189 return strReturn ;
190 }
191 #endregion
192
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
193 设置节点值设置节点值#region 设置节点值
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
194 /**//**//**//// <summary>
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
195 /**//// 功能:
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
196 /**//// 设置节点值
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
197 /**//// </summary>
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
198 /**//// <param name="strNode">节点的名称</param>
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
199 /**//// <param name="newValue">节点值</param>
200 public void SetXmlNodeValue(string xmlNodePath,string xmlNodeValue)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
201
{
202 try
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
203
{
204 //可以批量为符合条件的节点进行付值
205 XmlNodeList xmlNode=this.xmlDoc.SelectNodes(xmlNodePath);
206 if (!(xmlNode==null))
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
207
{
208 foreach(XmlNode xn in xmlNode)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
209
{
210 xn.InnerText = xmlNodeValue ;
211 }
212 }
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
213 /**//**//**//*
214 * 根据指定路径获取节点
215 XmlNode xmlNode = xmlDoc.SelectSingleNode(xmlNodePath) ;
216 //设置节点值
217 if (!(xmlNode==null))
218 xmlNode.InnerText = xmlNodeValue ;*/
219 }
220 catch(XmlException xmle)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
221
{
222 throw xmle ;
223 }
224 }
225 #endregion
226
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
227 设置节点的属性值设置节点的属性值#region 设置节点的属性值
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
228 /**//**//**//// <summary>
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
229 /**//// 功能:
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
230 /**//// 设置节点的属性值
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
231 /**//// </summary>
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
232 /**//// <param name="xmlNodePath">节点名称</param>
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
233 /**//// <param name="xmlNodeAttribute">属性名称</param>
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
234 /**//// <param name="xmlNodeAttributeValue">属性值</param>
235 public void SetXmlNodeAttributeValue(string xmlNodePath,string xmlNodeAttribute,string xmlNodeAttributeValue)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
236
{
237 try
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
238
{
239 //可以批量为符合条件的节点的属性付值
240 XmlNodeList xmlNode=this.xmlDoc.SelectNodes(xmlNodePath);
241 if (!(xmlNode==null))
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
242
{
243 foreach(XmlNode xn in xmlNode)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
244
{
245 XmlAttributeCollection xmlAttr = xn.Attributes ;
246 for(int i=0 ; i<xmlAttr.Count ; i++)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
247
{
248 if ( xmlAttr.Item(i).Name == xmlNodeAttribute )
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
249
{
250 xmlAttr.Item(i).Value = xmlNodeAttributeValue;
251 break ;
252 }
253 }
254 }
255 }
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
256 /**//**//**//*单个节点
257 //根据指定路径获取节点
258 XmlNode xmlNode = xmlDoc.SelectSingleNode(xmlNodePath) ;
259 if (!(xmlNode==null))
260 {//获取节点的属性,并循环取出需要的属性值
261 XmlAttributeCollection xmlAttr = xmlNode.Attributes ;
262 for(int i=0 ; i<xmlAttr.Count ; i++)
263 {
264 if ( xmlAttr.Item(i).Name == xmlNodeAttribute )
265 {
266 xmlAttr.Item(i).Value = xmlNodeAttributeValue;
267 break ;
268 }
269 }
270 }
271 */
272 }
273 catch(XmlException xmle)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
274
{
275 throw xmle ;
276 }
277 }
278 #endregion
279
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
280 添加添加#region 添加
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
281 /**//**//**//// <summary>
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
282 /**//// 获取XML文件的根元素
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
283 /**//// </summary>
284 public XmlNode GetXmlRoot()
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
285
{
286 return xmlDoc.DocumentElement ;
287 }
288
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
289 /**//**//**//// <summary>
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
290 /**//// 在根节点下添加父节点
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
291 /**//// </summary>
292 public void AddParentNode(string parentNode)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
293
{
294 try
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
295
{
296 XmlNode root = GetXmlRoot() ;
297 XmlNode parentXmlNode = xmlDoc.CreateElement(parentNode) ;
298 root.AppendChild(parentXmlNode) ;
299 }
300 catch(XmlException xmle)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
301
{
302 throw xmle ;
303 }
304 }
305
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
306 /**//**//**//// <summary>
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
307 /**//// 向一个已经存在的父节点中插入一个子节点
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
308 /**//// </summary>
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
309 /**//// <param name="parentNodePath">父节点</param>
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
310 /**//// <param name="childNodePath">字节点名称</param>
311 public void AddChildNode( string parentNodePath,string childnodename )
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
312
{
313 try
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
314
{
315 XmlNode parentXmlNode = xmlDoc.SelectSingleNode(parentNodePath) ;
316 if(!((parentXmlNode)==null))//如果此节点存在
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
317
{
318 XmlNode childXmlNode = xmlDoc.CreateElement(childnodename) ;
319 parentXmlNode.AppendChild( childXmlNode ) ;
320 }
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
321 else
{//如果不存在就放父节点添加
322 //this.GetXmlRoot().AppendChild(childXmlNode);
323 }
324
325 }
326 catch(XmlException xmle)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
327
{
328 throw xmle;
329 }
330 }
331
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
332 /**//**//**//// <summary>
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
333 /**//// 向一个节点添加属性
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
334 /**//// </summary>
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
335 /**//// <param name="NodePath">节点路径</param>
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
336 /**//// <param name="NodeAttribute">属性名</param>
337 public void AddAttribute( string NodePath , string NodeAttribute)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
338
{
339 privateAddAttribute(NodePath,NodeAttribute,"");
340 }
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
341 /**//**//**//// <summary>
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
342 /**////
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
343 /**//// </summary>
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
344 /**//// <param name="NodePath"></param>
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
345 /**//// <param name="NodeAttribute"></param>
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
346 /**//// <param name="NodeAttributeValue"></param>
347 private void privateAddAttribute( string NodePath , string NodeAttribute,string NodeAttributeValue)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
348
{
349 try
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
350
{
351 XmlNode nodePath = xmlDoc.SelectSingleNode( NodePath ) ;
352 if (!(nodePath==null))
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
353
{
354 XmlAttribute nodeAttribute = this.xmlDoc.CreateAttribute(NodeAttribute);
355 nodeAttribute.Value=NodeAttributeValue;
356 nodePath.Attributes.Append(nodeAttribute) ;
357 }
358 }
359 catch(XmlException xmle)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
360
{
361 throw xmle;
362 }
363 }
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
364 /**//**//**//// <summary>
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
365 /**//// 向一个节点添加属性,并付值
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
366 /**//// </summary>
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
367 /**//// <param name="NodePath">节点</param>
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
368 /**//// <param name="NodeAttribute">属性名</param>
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
369 /**//// <param name="NodeAttributeValue">属性值</param>
370 public void AddAttribute( string NodePath , string NodeAttribute,string NodeAttributeValue)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
371
{
372 privateAddAttribute(NodePath,NodeAttribute,NodeAttributeValue);
373 }
374 #endregion
375
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
376 删除删除#region 删除
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
377 /**//**//**//// <summary>
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
378 /**//// 删除节点的一个属性
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
379 /**//// </summary>
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
380 /**//// <param name="NodePath">节点所在的xpath表达式</param>
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
381 /**//// <param name="NodeAttribute">属性名</param>
382 public void DeleteAttribute( string NodePath , string NodeAttribute)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
383
{
384 XmlNodeList nodePath =this.xmlDoc.SelectNodes(NodePath);
385 if (!(nodePath==null))
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
386
{
387 foreach (XmlNode tempxn in nodePath)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
388
{
389 XmlAttributeCollection xmlAttr = tempxn.Attributes ;
390 for(int i=0 ; i<xmlAttr.Count ; i++)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
391
{
392 if ( xmlAttr.Item(i).Name == NodeAttribute)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
393
{
394 tempxn.Attributes.RemoveAt(i);
395 break ;
396 }
397 }
398 }
399 }
400 }
401
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
402 /**//**//**//// <summary>
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
403 /**//// 删除节点,当其属性值等于给定的值时
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
404 /**//// </summary>
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
405 /**//// <param name="NodePath">节点所在的xpath表达式</param>
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
406 /**//// <param name="NodeAttribute">属性</param>
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
407 /**//// <param name="NodeAttributeValue">值</param>
408 public void DeleteAttribute( string NodePath , string NodeAttribute , string NodeAttributeValue)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
409
{
410 XmlNodeList nodePath =this.xmlDoc.SelectNodes(NodePath);
411 if (!(nodePath==null))
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
412
{
413 foreach (XmlNode tempxn in nodePath)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
414
{
415 XmlAttributeCollection xmlAttr = tempxn.Attributes ;
416 for(int i=0 ; i<xmlAttr.Count ; i++)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
417
{
418 if ( xmlAttr.Item(i).Name == NodeAttribute && xmlAttr.Item(i).Value==NodeAttributeValue)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
419
{
420 tempxn.Attributes.RemoveAt(i);
421 break ;
422 }
423 }
424 }
425 }
426 }
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
427 /**//**//**//// <summary>
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
428 /**//// 删除节点
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
429 /**//// </summary>
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
430 /**//// <param name="tempXmlNode"></param>
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
431 /**//// <remarks></remarks>
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
432 public void DeleteXmlNode(string tempXmlNode)
{
433 XmlNodeList nodePath =this.xmlDoc.SelectNodes(tempXmlNode);
434 if (!(nodePath==null))
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
435
{
436 foreach(XmlNode xn in nodePath)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
437
{
438 xn.ParentNode.RemoveChild(xn);
439 }
440 }
441 }
442
443 #endregion
444
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
445 XML文档事件XML文档事件#region XML文档事件
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
446 /**//**//**//// <summary>
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
447 /**////
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
448 /**//// </summary>
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
449 /**//// <param name="src"></param>
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
450 /**//// <param name="args"></param>
451 private void nodeInsertEvent(Object src, XmlNodeChangedEventArgs args)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
452
{
453 //保存设置
454 SaveXmlDocument();
455 }
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
456 /**//**//**//// <summary>
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
457 /**////
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
458 /**//// </summary>
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
459 /**//// <param name="src"></param>
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
460 /**//// <param name="args"></param>
461 private void nodeDeleteEvent(Object src, XmlNodeChangedEventArgs args)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
462
{
463 //保存设置
464 SaveXmlDocument();
465 }
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
466 /**//**//**//// <summary>
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
467 /**////
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
468 /**//// </summary>
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
469 /**//// <param name="src"></param>
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
470 /**//// <param name="args"></param>
471 private void nodeUpdateEvent(Object src, XmlNodeChangedEventArgs args)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
472
{
473 //保存设置
474 SaveXmlDocument();
475 }
476 #endregion
477
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
478 保存XML文件保存XML文件#region 保存XML文件
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
479 /**//**//**//// <summary>
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
480 /**//// 功能:
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
481 /**//// 保存XML文件
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
482 /**////
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
483 /**//// </summary>
484 public void SaveXmlDocument()
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
485
{
486 try
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
487
{
488 //保存设置的结果
489 if( this.xmlFilePathType == enumXmlPathType.AbsolutePath )
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
490
{
491 Savexml( xmlFilePath ) ;
492 }
493 else if( this.xmlFilePathType == enumXmlPathType.VirtualPath )
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
494
{
495 Savexml(HttpContext.Current.Server.MapPath(xmlFilePath)) ;
496 }
497 }
498 catch(XmlException xmle)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
499
{
500 throw xmle;
501 }
502 }
503
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
504 /**//**//**//// <summary>
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
505 /**//// 功能:
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
506 /**//// 保存XML文件
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
507 /**//// </summary>
508 public void SaveXmlDocument(string tempXMLFilePath)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
509
{
510 try
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
511
{
512 //保存设置的结果
513 Savexml(tempXMLFilePath);
514 }
515 catch(XmlException xmle)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
516
{
517 throw xmle;
518 }
519 }
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
520 /**//**//**//// <summary>
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
521 /**////
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
522 /**//// </summary>
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
523 /**//// <param name="filepath"></param>
524 private void Savexml(string filepath)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
525
{
526 xmlDoc.Save(filepath);
527 }
528
529 #endregion
530
531 }
532
533}
534
535
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
转:
http://www.knowsky.com/340508.html
posted on
2007-07-06 16:40
Dragon-China
阅读(
422)
评论()
编辑
收藏
举报