Selecting the Parent Element with ..
A double period (..
)
indicates the parent of the current node. For example, the XPath
expression //@id
identifies all
id
attributes in the document.
Therefore, //@id/..
identifies
all elements in the document that have id
attributes. The XPath expression
//middle_initial/../first_name
identifies all first_name
elements that are siblings of middle_initial
elements in the document.
Applied to Example 9-1,
this selects <first_name>Richard</first_name>
but not <first_name>Alan</first_name>
.
Get XML in a Nutshell, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.