Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does '@comment()' do in XPath?

Tags:

xml

xpath

I have been working on an XPath parser, with the grammars here as a reference. I was surpised that an @ symbol with a KindTest is possible. The KindTest can be node(), comment(), text(), or processing-instruction(xyz) (they test for the Node Type).

My question is what these do when combined with an @ sign; . What do @processing-instruction("xyz"), @comment(), @node, and @text do? Are they searching for attributes with processing instructions or comments in them?

like image 481
Nate Glenn Avatar asked Jun 20 '13 20:06

Nate Glenn


1 Answers

@comment() is a valid XPath location path step expression that is guaranteed to return nothing. Technically it is asking for all comment nodes found along the attribute axis (and you will never find any).

I tell my students that /.. is a more compact and readable way of writing a complete location path that is guaranteed to return nothing. Technically it is asking for the parent of the root node.

like image 163
G. Ken Holman Avatar answered Sep 20 '22 06:09

G. Ken Holman