XmlNodeList students = doc.DocumentElement.ChildNodes;//Student节点集合 foreach (XmlNode stu in students) { XmlElement element = (XmlElement)stu; string stuId = element.GetAttribute("StuID"); XmlNode nameNode = element.SelectSingleNode("StuName");//获取Person节点的Name节点 string name = nameNode.InnerText; Console.WriteLine(stuId + "," + name); }
案例xml文件
时间: 2024-11-05 02:39:02