String xml=
"<?xml version="1.0" encoding"utf-8" ?>
<users><user id = "1001" >
<name> 张三 </name>
<email> 123456789@136.com </email>
<phone> 13400000000 </phone>
</user>
"1002" <name> 李四 <email> 123456789@126.com <phone> 15800000000
</users>";
(); ); //查找<users> //获取到所有<users>的子节点 ).; //遍历所有子节点 ) "节点的ID为: "GetAttribute"id")); } } }static void ReadParseXml() { XmlDocument xmlDoc =newXmlDocument();
//获取xml文件地址 xmlDoc.Load("E:/Data/VisualStudio/C#/app001/ConsoleApp/App01/userlist.xml");
//加载xml字符串 string xml="........."
xmlDoc.Loadxml(xml); //查找<users> XmlNode root SelectSingleNode"users"); //获取到所有<users>的子节点 XmlNodeList nodeList rootChildNodes; //遍历所有子节点 foreach ( xn in nodeList) { XmlElement xe XmlElement)xn subList xe xmlNode subListif"name"Equals(xmlNodeName)) ConsoleWriteLine"姓名:"+ xmlNodeInnerText} else"email""邮箱:"} } }
ReadParseXml2
对XmlDocument类 的讲解,请看:http://www.cnblogs.com/kissdodog/archive/2013/02/24/2924236.html
原文链接:https://www.f2er.com/xml/295665.html