.net操纵xml文件类(c#)(4)

2008-02-22 09:38:24来源:互联网 阅读 ()

新老客户大回馈,云服务器低至5折


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 ;
422 }
423 }
424 }
425 }
426 }
427 /**//// <summary>
428 /// 删除节点
429 /// </summary>
430 /// <param name="tempXmlNode"></param>
431 /// <remarks></remarks>
432 public void DeleteXmlNode(string tempXmlNode){
433 XmlNodeList nodePath =this.xmlDoc.SelectNodes(tempXmlNode);
434 if (!(nodePath==null))
435 {
436 foreach(XmlNode xn in nodePath)
437 {
438 xn.ParentNode.RemoveChild(xn);
439 }
440 }
441 }
442
443 #endregion
444
445 XML文档事件#region XML文档事件
446 /**//// <summary>
447 ///
448 /// </summary>
449 /// <param name="src"></param>
450 /// <param name="args"></param>
451 private void nodeInsertEvent(Object src, XmlNodeChangedEventArgs args)
452 {
453 //保存设置
454 SaveXmlDocument();
455 }
456 /**//// <summary>
457 ///
458 /// </summary>
459 /// <param name="src"></param>
460 /// <param name="args"></param>
461 private void nodeDeleteEvent(Object src, XmlNodeChangedEventArgs args)
462 {
463 //保存设置
464 SaveXmlDocument();
465 }
466 /**//// <summary>
467 ///
468 /// </summary>
469 /// <param name="src"></param>
470 /// <param name="args"></param>
471 private void nodeUpdateEvent(Object src, XmlNodeChangedEventArgs args)
472 {
473 //保存设置
474 SaveXmlDocument();
475 }
476 #endregion
477
478 保存XML文件#region 保存XML文件
479 /**//// <summary>
480 /// 功能:
481 /// 保存XML文件
482 ///
483 /// </summary>
484 public void SaveXmlDocument()
485 {
486 try
487 {
488 //保存设置的结果
489 if( this.xmlFilePathType == enumXmlPathType.AbsolutePath )
490 {
491 Savexml( xmlFilePath ) ;
492 }
493 else if( this.xmlFilePathType == enumXmlPathType.VirtualPath )
494 {
495 Savexml(HttpContext.Current.Server.MapPath(xmlFilePath)) ;
496 }
497 }
498 catch(XmlException xmle)
499 {
500 throw xmle;
501 }
502 }
503
504 /**//// <summary>
505 /// 功能:
506 /// 保存XML文件
507 /// </summary>

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:ASP.NET底层架构探索之进入.NET运行时

下一篇:关于2.0 中的用户控件编程使用