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

        /// <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;
       }
posted @ 2016-06-15 15:41  寒夜美美  阅读(370)  评论(0编辑  收藏  举报