Magazine |
| | Community |
| | Workshop |
| | Tools & Samples |
| | Training |
| | Site Info |
|
|
||||||||
|
The $any$ keyword means that a condition will hold true if any item in a set meets that condition. The $all$ keyword means that a condition will hold true only if all elements in a set meet the condition. The $any$ and $all$ keywords appear before the expression.
You use $any$ and $all$ when using comparison operations. For example, the following expression means return book elements where the first author element is equal to "Bob":
book[author="Bob"]
The following expression means return book elements where any author element is "Bob":
book[$any$ author="Bob"]
The following expression means return book elements where all author elements are "Bob":
book[$all$ author = "Bob"]
When a book only has one "author" child element, these three expressions are equivalent.
The first expression provides the best performance results of the three, because it examines only the first child element. The second expression traverses children until an author child with the value "Bob" is found (or none is found), and the third traverses all children.
Operations on sets of elements can often return results that contradict your expectations. For example, it is possible to define two filter patterns that, because one uses the equality operator and the other uses the inequality operator, you would expect to return different results. However, when performing set operations, it is possible that these two filter patterns return the same result.
Consider the filter patterns "myelement[$any$ mychild $eq$ a]" and "myelement[$any$ mychild $ne$ a]", applied to the following XML data:
<myelement> <mychild>a</mychild> <mychild>b</mychild> </myelement>
The first pattern is able to find a myelement element that has a mychild element equal to "a"; the second pattern is also able to find a myelement element that has a mychild element that is not equal to "a". Both filter patterns return the same element.
Use the $all$ keyword to indicate that every element in the set must match the supplied value.
Examples
Find all author elements where any one of the last names is Bob:
author[$any$ last-name = "Bob"]
Find all author elements where none of the last-name elements are Bob:
author[$all$ last-name != "Bob"]
See Also
Does this content meet your programming needs? Write us!
© 1998 Microsoft Corporation. All rights reserved. Terms of use.