如何根据父节点的属性值查询XML节点

时间:2010-08-19 07:59:54

标签: c# .net xml xpath

我有一个看起来像这样的XML:

<Library>
<Author Name = "JRR Tolkien">
<Book Title = "Lord Of the Rings" />
<Book Title = "The Hobbit" />
</Author>
<Author Name = "JK Rowling">
<Book Title = "Harry Potter and the Sorcerers Stone" />
<Book Title = "Harry Potter and the Prisoner of Azkaban" />
</Author>
</Library>

选择父“作者”节点的值为“JK罗琳”的所有“预订”节点的XPath是什么?

1 个答案:

答案 0 :(得分:3)

这是最直观和严格的选择,它选择所有Author Name属性为'JK Rowling'作为父级的书籍。 Author还必须将Library作为父级。

/Library/Author[@Name='JK Rowling']/Book