XmlFiles.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using System;
  2. using System.IO;
  3. using System.Xml;
  4. namespace AutoUpdate
  5. {
  6. /// <summary>
  7. /// XmlFiles 的摘要说明。
  8. /// </summary>
  9. public class XmlFiles:XmlDocument
  10. {
  11. #region 字段与属性
  12. private string _xmlFileName;
  13. public string XmlFileName
  14. {
  15. set{_xmlFileName = value;}
  16. get{return _xmlFileName;}
  17. }
  18. #endregion
  19. public XmlFiles(string xmlFile)
  20. {
  21. XmlFileName = xmlFile;
  22. this.Load(xmlFile);
  23. }
  24. /// <summary>
  25. /// 给定一个节点的xPath表达式并返回一个节点
  26. /// </summary>
  27. /// <param name="node"></param>
  28. /// <returns></returns>
  29. public XmlNode FindNode(string xPath)
  30. {
  31. XmlNode xmlNode = this.SelectSingleNode(xPath);
  32. return xmlNode;
  33. }
  34. /// <summary>
  35. /// 给定一个节点的xPath表达式返回其值
  36. /// </summary>
  37. /// <param name="xPath"></param>
  38. /// <returns></returns>
  39. public string GetNodeValue(string xPath)
  40. {
  41. XmlNode xmlNode = this.SelectSingleNode(xPath);//5~1-a-s-p-x
  42. return xmlNode.InnerText;
  43. }
  44. /// <summary>
  45. /// 给定一个节点的表达式返回此节点下的孩子节点列表
  46. /// </summary>
  47. /// <param name="xPath"></param>
  48. /// <returns></returns>
  49. public XmlNodeList GetNodeList(string xPath)
  50. {
  51. XmlNodeList nodeList = this.SelectSingleNode(xPath).ChildNodes;
  52. return nodeList;
  53. }
  54. }
  55. }