static void Main(string[] args) { XmlTextReader reader = new XmlTextReader(@"D:zyvisual studio 2010第11周十一假期MVCInsigma.XmlXmlXMLFile1.xml"); while (reader.Read()) { if (reader.NodeType == System.Xml.XmlNodeType.Element) { reader.Read(); if (reader.NodeType == System.Xml.XmlNodeType.Text) { Console.WriteLine(reader.Value); } } } Console.ReadKey(); }
xml文件:
1 <students> 2 <student> 3 <name>张杰</name> 4 <age>20</age> 5 <gender>男</gender> 6 </student> 7 </students>
运行结果: