开发者

Grandchildren of an element (XPath)

I'm searching for a XPath ex开发者_StackOverflow社区presssion, which gives me all grandchildren of an element.

Is this correct: child/child/* ?


*/* gives all grandchildren see http://www.caucho.com/resin-3.1/doc/xpath.xtp


Is this correct: child/child/* ?

No,

child

selects all children elements of the current node, whose name is child.

child/child

selects all elements named child that ara children of any element named child that is a child of the current node. So, the above expression selects all grandchildren of the current node, that are named child and whose parents are also named child. This is closest to "grandchildren of an element".

The XPath expression you are asking about:

child/child/*

selects all elements (regardless of name) that are children of elements named child that are children of elements named child that are children of the current node. These are some of the current node's grand-grand-children (children of the grandchildren).

To answer completely the question, the following expression selects all grandchildren of the current node:

*/node()

These are all nodes that are children of all elements that are children of the current node.

Note the following:

  1. Only elements and the document node can have children.

  2. Any node (with the exception of the document node), not only an element node, can be and usually is a child of some other node. Therefore, there can be grandchildren that are not elements -- such as text nodes, comment nodes and processing-instruction nodes. Attributes and namespace nodes are technically not children.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜