现在的位置: 首页 > 综合 > 正文

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

2012年07月13日 ⁄ 综合 ⁄ 共 388字 ⁄ 字号 评论关闭

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 }

抱歉!评论已关闭.