(转载)读取xml中的指定节点的值

时间:2022-05-06 20:53:23
        /// <summary> 
       /// 读取xml中的指定节点的值
       /// </summary> 
       private string ReadXmlNode(string filename)
       {
           string result = "-1";
           XmlDocument xmlDoc = new XmlDocument();
           try
           {
               xmlDoc.LoadXml(filename);
               //读取Activity节点下的数据。SelectSingleNode匹配第一个Activity节点
               XmlNode root = xmlDoc.SelectSingleNode("//head");//当节点Workflow带有属性是,使用SelectSingleNode无法读取       
               if (root != null)
                   result = (root.SelectSingleNode("code")).InnerText;
 
           }
           catch //(Exception e)
           {
               //显示错误信息
           }
           return result;
       }