取任意xml节点中某个属性值的方法

前端之家收集整理的这篇文章主要介绍了取任意xml节点中某个属性值的方法前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。


publicstringGetXmlNodeValue(stringstrXml,stringstrNodeName,stringstrValueName)
{
try
{
System.Xml.XmlDocumentxmlDoc
=newSystem.Xml.XmlDocument();
xmlDoc.LoadXml(strXml);
System.Xml.XmlNodexNode
=xmlDoc.SelectSingleNode("//"+strNodeName+"");
stringstrValue=xNode.Attributes[strValueName].Value;
returnstrValue;
}
catch(Exceptionex)
{
returnex.Message; } }

原文链接:https://www.f2er.com/xml/296732.html

猜你在找的XML相关文章