325 }
326 catch(XmlException xmle)
327 {
328 throw xmle;
329 }
330 }
331
332 /** <summary>
333 /// 向一个节点添加属性
334 /// </summary>
335 /// <param name="NodePath">节点路径</param>
336 /// <param name="NodeAttribute">属性名</param>
337 public void AddAttribute( string NodePath , string NodeAttribute)
338 {
339 privateAddAttribute(NodePath,NodeAttribute,"");
340 }
341 /** <summary>
342 ///
343 /// </summary>
344 /// <param name="NodePath"></param>
345 /// <param name="NodeAttribute"></param>
346 /// <param name="NodeAttributeValue"></param>
347 private void privateAddAttribute( string NodePath , string NodeAttribute,string NodeAttributeValue)
348 {
349 try
350 {
351 XmlNode nodePath = xmlDoc.SelectSingleNode( NodePath ) ;
352 if (!(nodePath==null))
353 {
354 XmlAttribute nodeAttribute = this.xmlDoc.CreateAttribute(NodeAttribute);
355 nodeAttribute.Value=NodeAttributeValue;
356 nodePath.Attributes.Append(nodeAttribute) ;
357 }
358 }
359 catch(XmlException xmle)
360 {
361 throw xmle;
362 }
363 }
364 /** <summary>
365 /// 向一个节点添加属性,并付值
366 /// </summary>
367 /// <param name="NodePath">节点</param>
368 /// <param name="NodeAttribute">属性名</param>
369 /// <param name="NodeAttributeValue">属性值</param>
370 public void AddAttribute( string NodePath , string NodeAttribute,string NodeAttributeValue)
371 {
372 privateAddAttribute(NodePath,NodeAttribute,NodeAttributeValue);
373 }
374 #endregion
375
376 删除#region 删除
377 /** <summary>
378 /// 删除节点的一个属性
379 /// </summary>
380 /// <param name="NodePath">节点所在的xpath表达式</param>
381 /// <param name="NodeAttribute">属性名</param>
382 public void DeleteAttribute( string NodePath , string NodeAttribute)
383 {
384 XmlNodeList nodePath =this.xmlDoc.SelectNodes(NodePath);
385 if (!(nodePath==null))
386 {
387 foreach (XmlNode tempxn in nodePath)
388 {
389 XmlAttributeCollection xmlAttr = tempxn.Attributes ;
390 for(int i=0 ; i<xmlAttr.Count ; i++)
391 {
392 if ( xmlAttr.Item(i).Name == NodeAttribute)
393 {
394 tempxn.Attributes.RemoveAt(i);
395 break ;
396 }
397 }
398 }
399 }
400 }
401
402 /** <summary>
403 /// 删除节点,当其属性值等于给定的值时
404 /// </summary>
405 /// <param name="NodePath">节点所在的xpath表达式</param>
406 /// <param name="NodeAttribute">属性</param>
407 /// <param name="NodeAttributeValue">值</param>
408 public void DeleteAttribute( string NodePath , string NodeAttribute , string NodeAttributeValue)
409 {
410 XmlNodeList nodePath =this.xmlDoc.SelectNodes(NodePath);
411 if (!(nodePath==null))
412 {
413 foreach (XmlNode tempxn in nodePath)
414 {
415 XmlAttributeCollection xmlAttr = tempxn.Attributes ;
416 for(int i=0 ; i<xmlAttr.Count ; i++)
417 {
418 if ( xmlAttr.Item(i).Name == NodeAttribute && xmlAttr.Item(i).Value==NodeAttributeValue)
419 {
420 tempxn.Attributes.RemoveAt(i);
421 break ;
326 catch(XmlException xmle)
327 {
328 throw xmle;
329 }
330 }
331
332 /** <summary>
333 /// 向一个节点添加属性
334 /// </summary>
335 /// <param name="NodePath">节点路径</param>
336 /// <param name="NodeAttribute">属性名</param>
337 public void AddAttribute( string NodePath , string NodeAttribute)
338 {
339 privateAddAttribute(NodePath,NodeAttribute,"");
340 }
341 /** <summary>
342 ///
343 /// </summary>
344 /// <param name="NodePath"></param>
345 /// <param name="NodeAttribute"></param>
346 /// <param name="NodeAttributeValue"></param>
347 private void privateAddAttribute( string NodePath , string NodeAttribute,string NodeAttributeValue)
348 {
349 try
350 {
351 XmlNode nodePath = xmlDoc.SelectSingleNode( NodePath ) ;
352 if (!(nodePath==null))
353 {
354 XmlAttribute nodeAttribute = this.xmlDoc.CreateAttribute(NodeAttribute);
355 nodeAttribute.Value=NodeAttributeValue;
356 nodePath.Attributes.Append(nodeAttribute) ;
357 }
358 }
359 catch(XmlException xmle)
360 {
361 throw xmle;
362 }
363 }
364 /** <summary>
365 /// 向一个节点添加属性,并付值
366 /// </summary>
367 /// <param name="NodePath">节点</param>
368 /// <param name="NodeAttribute">属性名</param>
369 /// <param name="NodeAttributeValue">属性值</param>
370 public void AddAttribute( string NodePath , string NodeAttribute,string NodeAttributeValue)
371 {
372 privateAddAttribute(NodePath,NodeAttribute,NodeAttributeValue);
373 }
374 #endregion
375
376 删除#region 删除
377 /** <summary>
378 /// 删除节点的一个属性
379 /// </summary>
380 /// <param name="NodePath">节点所在的xpath表达式</param>
381 /// <param name="NodeAttribute">属性名</param>
382 public void DeleteAttribute( string NodePath , string NodeAttribute)
383 {
384 XmlNodeList nodePath =this.xmlDoc.SelectNodes(NodePath);
385 if (!(nodePath==null))
386 {
387 foreach (XmlNode tempxn in nodePath)
388 {
389 XmlAttributeCollection xmlAttr = tempxn.Attributes ;
390 for(int i=0 ; i<xmlAttr.Count ; i++)
391 {
392 if ( xmlAttr.Item(i).Name == NodeAttribute)
393 {
394 tempxn.Attributes.RemoveAt(i);
395 break ;
396 }
397 }
398 }
399 }
400 }
401
402 /** <summary>
403 /// 删除节点,当其属性值等于给定的值时
404 /// </summary>
405 /// <param name="NodePath">节点所在的xpath表达式</param>
406 /// <param name="NodeAttribute">属性</param>
407 /// <param name="NodeAttributeValue">值</param>
408 public void DeleteAttribute( string NodePath , string NodeAttribute , string NodeAttributeValue)
409 {
410 XmlNodeList nodePath =this.xmlDoc.SelectNodes(NodePath);
411 if (!(nodePath==null))
412 {
413 foreach (XmlNode tempxn in nodePath)
414 {
415 XmlAttributeCollection xmlAttr = tempxn.Attributes ;
416 for(int i=0 ; i<xmlAttr.Count ; i++)
417 {
418 if ( xmlAttr.Item(i).Name == NodeAttribute && xmlAttr.Item(i).Value==NodeAttributeValue)
419 {
420 tempxn.Attributes.RemoveAt(i);
421 break ;