如何获取xml任意节点中某个属性值


View Code
1 public string GetXmlNodeValue(string strXml,string strNodeName,string strValueName)
2 {powered by 25175.net
3 try
4 {
5 System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();
6 xmlDoc.LoadXml(strXml);
7 System.Xml.XmlNode xNode = xmlDoc.SelectSingleNode("//" + strNodeName + "");
8 string strValue = xNode.Attributes[strValueName].Value;
9 return strValue;
10 }
11 catch (Exception ex)
12 {
13 return ex.Message;
14 }
15
16 }
posted @ 2011-06-01 19:26  笨笨的菜鸟  阅读(7547)  评论(0编辑  收藏  举报