public string GetXmlNodeValue(string strXml,string strNodeName,string strValueName)
{
try
{
System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();
xmlDoc.LoadXml(strXml);
System.Xml.XmlNode xNode = xmlDoc.SelectSingleNode("//" + strNodeName + "");
string strValue = xNode.Attributes[strValueName].Value;
return strValue;
}
catch (Exception ex)
{
return ex.Message;
}
}
取xml任意节点中某个属性值的方法
最新推荐文章于 2023-06-08 16:33:51 发布
本文介绍了一种通过C#编程语言从XML字符串中提取特定节点属性值的方法。该方法使用了System.Xml命名空间下的XmlDocument类来加载XML内容,并通过SelectSingleNode方法定位到指定节点,最终返回该节点的属性值。
560

被折叠的 条评论
为什么被折叠?



