I was learning XPath using the following xml document: http://www.w3schools.com/xpath/xpath_examples.asp
Now, when I execute the query:
bookstore/book/author[contains(.,'G')]
I get the result: Giada De Laurentiis, James McGovern as expected. Now, since contains() returns a boolean value, I expected the following query to return all authors:
bookstore/book/author[true]
however, it returns an empty set. Can somebody explain?
The above expression selects all
bookstore/book/authorelements that have a child element namedtrue. In the provided XML document noauthorelement has a child namedtrue— therefore the XPath expression selects nothing.In a comment the OP asks:
contains()never returns (the string) “true” — it returns the boolean valuetrue()— this is different from the string “true”.Explanation:
You are confused by the fact that the serialization of the boolean value
true()to sting is the string “true”.This fact doesnt mean that the string “true” and the boolean value
true()are identical.