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

I am working on an XPath parser, here grammar is used as a reference here . I was sure that the @ character with KindTest is possible. KindTest can be node() , comment() , text() or processing-instruction(xyz) (they test the Node Type ).

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

+7
source share
2 answers

@comment() is a valid XPath location path path expression that is guaranteed to return nothing. Technically, it queries all the comment nodes found along the axis of the attributes (and you will never find them).

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, he asks for the parent root node.

+11
source

NateGlenn, this is not what @comment() embedded in the grammar. It's just that the combination of @ and comment() not specifically prohibited.

As you know, @ is an abbreviation for the attribute:: axis. Axes are built into the grammar. Node tests (e.g. node() and comment() ) are embedded in a separate part of the grammar.

@comment() must be a special case for the @comment() combination to be forbidden by grammar. You can think of other combinations that do not make much sense, except to return an empty set of nodes: parent::text() , for example.

It is more likely that sqrt(-1) or sqrt(-1) would be forbidden by C.

+7
source

All Articles