<pre name="code" class="csharp">//xml类对象建立 对xml文件的操作
XmlDocument doc = new XmlDocument();
//加载Xml文件
doc.Load("aa.xml");
//获取根节点
XmlElement rootElem = doc.DocumentElement;
//找出节点个数(metadata)
XmlNodeList childNodes = rootElem.SelectNodes("//metadata"); //组合结点
//遍历所有的子节点
foreach (XmlElement element in childNodes)
{
string id = element.GetElementsByTagName("id")[0].InnerText;
string name = element.GetElementsByTagName("name")[0].InnerText;
string sex = element.GetElementsByTagName("sex")[0].InnerText;
string age = element.GetElementsByTagName("age")[0].InnerText;
Console.WriteLine("id = " + id + " name " + name + " sex = " + sex + " age " + age);
}<span style="white-space:pre"> </span>
<img src="https://img-blog.csdn.net/20151231103951782?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />