tags:

views:

41

answers:

1

I have an XML which looks something like this:

<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>

What is the XPath to select all the "Book" nodes whose parent "Author" node has the value "JK Rowling"?

+3  A: 

This is properly more most intuitive and strict which selects all the books which have a Author which Name attribute is 'JK Rowling' as a parent. And the Author must also have the Library as a parent.

/Library/Author[@Name='JK Rowling']/Book
lasseespeholt
+1 for the second option.
Jon Skeet
Yes, the 2nd option is much clearer. I was about to post something similar, but you edited your answer before ;)
Thomas Levesque
I totally agree with you both. So I deleted the first because it did not do any good.
lasseespeholt