저는 Linq를 C#으로 XML에 사용하기 시작했습니다. 나는 책에 관한 정보를 담고있는 XML 파일을 가지고있다.XDocument 읽기 하위 요소
<?xml version="1.0"?>
<catalog>
<book id="bk112">
<author>Galos, Mike</author>
<title>Visual Studio 7: A Comprehensive Guide</title>
<genre>Computer</genre>
<price>49.95</price>
<publish_date>2001-04-16</publish_date>
<description>Microsoft Visual Studio 7 is explored in depth,
looking at how Visual Basic, Visual C++, C#, and ASP+ are
integrated into a comprehensive development
environment.</description>
</book>
</catalog>
나는 나 저자의 목록과 XML 파일에서 도서 목록 얻을 수 있도록 코드를 작성하는 관리했습니다 :
public List<string> GetBooks()
{
XDocument document = XDocument.Load(XMLFileLocation);
var query = from t in document.Descendants("title")
select t.Value;
return query.ToList<string>();
}
을
XML 파일은이 구조를 가지고
그러나 특정 책에 대한 정보를 얻을 수있는 방법을 만드는 방법을 어떻게 진행해야할지 모르겠습니다. 예 :
GetBookAuthor("MyBook");
어떻게하면됩니까?