System.Xml 命名空间
https://msdn.microsoft.com/zh-cn/library/gg145036(v=vs.110).aspx
1.通过 XmlDocument获取稳定内容
2.通过XmlNodeList 找到节点数据
private void List_Click(object sender, RoutedEventArgs e)
{
string xmlStr = getData();
StringBuilder rtn = new StringBuilder();
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(xmlStr);
XmlNodeList xmlNodeList = xmlDoc.GetElementsByTagName("root");
foreach (XmlNode xmlNode in xmlNodeList)
{
//家长节点
XmlNodeList childXmlNodes1 = xmlNode.ChildNodes;
foreach (XmlNode childXmlNode1 in childXmlNodes1)
{
if (childXmlNode1.Name == "resultInfo")
{
//成员列表
XmlNodeList childXmlNodes2 = childXmlNode1.ChildNodes;
foreach (XmlNode childXmlNode2 in childXmlNodes2)
{
if (childXmlNode2.Name == "NAME")
{
rtn.Append(childXmlNode2.InnerText);
}
}
}
}
}
}
private string getData()
{
return "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + @"
<root>
<resultInfo>
<NAME>姓名</NAME>
<SEX>性别</SEX>
<error_msg> 成功!或者error:xxx </error_msg>
<remark>备注</remark>
</resultInfo>
</root>
";
}
原文:http://www.cnblogs.com/xcsn/p/4381195.html