Section 9.8.  XPath Unions

JavaScript Editor Free JavaScript Editor     JavaScript Debugger 




Main Page

Previous Page
Next Page

9.8. XPath Unions

Going back to my original comparison that XPath is to XML what an SQL SELECT is to a relational database, there is yet another similarity: unions. In XPath, unions return all nodes in both node sets. This can be quite useful when you're unsure of exactly what you're looking for or working with. For example, let's say that we want either the child elements of the third book node or the attributes. One method would be to use two separate XPath statements. Although this method would work, like most programmers, I'm basically lazy and would rather do it all in one statement by using the union operator (|), as shown here.

//book[3]/* | //book[3]/@*


Previous Page
Next Page




JavaScript Editor Free JavaScript Editor     JavaScript Debugger


©