Quackit Logo
HTML
CSS
Scripting
Database
Hosting
Design
XML
Website builder

XPath Node Test

In the previous lesson we saw an example of a node test. We used the node test in our expression when selecting a node from our XML document.

In this lesson, we'll look into node tests a little more closely.

Node Test Syntax

To refresh our memory, a node test is part of an expression to retrieve one or more nodes. Here's where a node test goes within our expression:

axis::node_test

If you have one or more predicates, your node test comes before the predicate/s:

axis::node_test[predicate/s]

Node Test Example

In the following example, "title" is the node test:

child::title

More Node Tests

Apart from using the name of a node or a wildcard (to select unknown nodes), you can also use the following node tests:

Node TestDescription
comment()Selects nodes that are comments.
node()Selects nodes of any type.
processing-instruction()Selects nodes that are processing instructions. You can specify which processing instruction to select by providing it's name in the parentheses.
text()Selects a text node.

Enjoy this page?

  1. Add this page to your Favorites
  2. Link to this page (copy/paste into your own website or blog):
  3. Link to Quackit using one of these banner ads.

Thanks for supporting Quackit!