public static string ReadXmlNodes(string xml, string node = "//id_no")
{
string text = string.Empty;
XmlDocument xmlDoc = new XmlDocument();
try
{
xmlDoc.LoadXml(xml);
XmlNode xn = xmlDoc.SelectSingleNode(node);
text = xn?.InnerText;
if(node =="//error")
{
XmlElement xe = (XmlElement)xn;
for (int i = 0; i < xe?.Attributes?.Count; i++)
{
//属性值
if (xe.Attributes[i].Name == "info")
{
text = xe.Attributes[i].InnerText;
}
}
}
}
catch (Exception ex)
{
}
return text;
}
C# 获取xml节点的值和属性
于 2023-06-08 16:33:51 首次发布