Select Comment with xPath by Comment-Text
How can I select the next node after an defined comment? I know the text of the comment and need the next nodes.
Bes开发者_如何学Got regards Christoph
Supposing the comment is a child of the current node, and the comment's text is "comment-text"
, then the following XPath expression selects the first element (sibling) that follows the comment node:
comment()[. = 'comment-text'][1]/following-sibling::*[1]
If we want the following element to be selected (regardless if it is sibling of the comment or not), the corresponding XPath expression is:
comment()[. = 'comment-text'][1]/following::*[1]
精彩评论