Skip to main content
XMLDir

Search 169 pages — formats, namespaces, parser messages, schema errors and tools.

XPath axe

child:: axis

Immediate children. The default axis, which is why it is almost never written out.

Every unprefixed step is a child:: step: `lines/line` means `child::lines/child::line`. It selects immediate children only — grandchildren need another step, or the descendant axis.

Writing it explicitly is rare but occasionally clearer when several axes appear in one expression.

Syntax
child::name — or just name
Returns
node-set
Kind
Axe
Version
XPath 1.0 (libxml2)

Worked examples

Each result below is what the evaluator returned, asserted on every test run. An empty result means an empty node-set — which is an answer, not an error.

  • count(/order/lines/line)on order.xmlRun
    3
  • count(/child::order/child::lines/child::line)on order.xmlRun
    3
  • count(/order/line)on order.xmlRun
    0

    Zero: <line> is a grandchild of <order>, not a child.

Run your own expression

What catches people out

  • It does not reach grandchildren. A path that skips a level selects nothing, silently.
  • The child axis never selects attributes — those live on their own axis.

The sample documents

Every example on this page runs against this document. The sitemap one is namespaced on purpose — almost every real XML document is, and that changes which expressions match.

order.xml
<?xml version="1.0" encoding="UTF-8"?>
<order id="A-1001" tier="gold">
  <customer country="NO">Ada Lovelace</customer>
  <lines>
    <line sku="WIDGET-1" qty="2"><price>14.50</price></line>
    <line sku="WIDGET-2" qty="1"><price>39.00</price></line>
    <line sku="GIFT-WRAP" qty="1"><price>0.00</price></line>
  </lines>
  <note>  Deliver after 09:00  </note>
</order>

Related

All 34 XPath entries

Get started

Bring order to the XML your team can't afford to ignore.

Create a free account and get a private workspace to search, validate, diff, and monitor your XML feeds, sitemaps, schemas, and vendor integrations.