首页 > 代码库 > 读取xml中的指定节点的值

读取xml中的指定节点的值

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/// <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;
       }