最近公司让我写一个软件更新器。其中要要用到xml文档读取相关的配置信息。来公司实习快两个月了,看了许多以前没见过的技术。留下来以备以后回顾
/// <summary> /// 给定一个节点的xPath表达式并返回一个节点 /// </summary> /// <param name="node"></param> /// <returns></returns> public XmlNode FindNode(string xPath) { XmlNode xmlNode = this.SelectSingleNode(xPath); return xmlNode; } /// <summary> /// 给定一个节点的xPath表达式返回其值 /// </summary> /// <param name="xPath"></param> /// <returns></returns> public string GetNodeValue(string xPath) { XmlNode xmlNode = this.SelectSingleNode(xPath); if (xmlNode == null) { return string.Empty; } else { return xmlNode.InnerText; } } /// <summary> /// 给定一个节点的表达式返回此节点下的孩子节点列表 /// </summary> /// <param name="xPath"></param> /// <returns></returns> public XmlNodeList GetNodeList(string xPath) { var nodeList = this.SelectSingleNode(xPath); if (nodeList == null) { return null; } else { return nodeList.ChildNodes; } }