以下面的xml文件为例: [html] view plain copy <?xml version="1.0"?> <info> <book id="b1" lang="en"> <name>c++</name> <price>570</price> </book> <book id="b2" lang="en"> <name>c#</name> <price>250</price> </book> </info> 使用System.Xml.XmlDocument来解析,如下:以下面的xml文件为例:以下面的xml文件为例: [csharp] view plain copy XmlDocument xmlDocument = new XmlDocument(); xmlDocument.Load(@"file.xml"); foreach (XmlElement book in xmlDocument.SelectNodes(@"info/book")) { // if you know attribute name simply use GetAttribute e.g. Console.WriteLine("id value: {0}.", book.GetAttribute("id")); // if you don't know attribute names you can loop e.g. foreach (XmlAttribute attribute in book.Attributes) { Console.WriteLine("attribute with name {0} has value {1}.", attribute.Name, attribute.Value); } }