我认为您不能“合法地”仅加载XML文件的一部分,因为那样的话它将是错误的格式(某处缺少关闭元素)。
使用LINQ-to-XML,您可以执行
var doc =Xdocument.Load("yourfilepath")。从那里只是查询所需的数据,就像这样说:var authors = doc.Root.Elements().Select( x => x.Element("Author") );HTH。
编辑:
好的,只是为了使它成为更好的示例,请尝试以下操作(使用@JWL_的建议改进):
using System;using System.Xml.Linq;namespace ConsoleApplication1 { class Program { static void Main( string[] args ) { Xdocument doc = Xdocument.Load( "XMLFile1.xml" ); var authors = doc.Descendants( "Author" ); foreach ( var author in authors ) { Console.WriteLine( author.Value ); } Console.ReadLine(); } }}您将需要调整路径
Xdocument.Load()以指向您的XML文件,但是其余的应该起作用。询问有关您不了解的部分的问题。


![从XML读取数据[重复] 从XML读取数据[重复]](http://www.mshxw.com/aiimages/31/470691.png)
