Skip to main content
XMLDir

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

XPath function

boolean() and not()

Converts to true or false. A node-set is true when it is non-empty — which is why [not(x)] means 'has no x'.

boolean() applies XPath's truthiness rules: a non-empty node-set is true, a non-empty string is true, and a number is true unless it is zero or NaN. not() negates the result.

The node-set rule is the useful one. [x] as a predicate means 'has a child x', and [not(x)] means 'has no child x'. That is how you find missing elements.

Syntax
boolean(object) → boolean
Returns
boolean
Kind
Function
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(//url[not(*[local-name()='lastmod'])])on sitemap.xmlRun
    0

    Zero — because //url matches nothing in a namespaced document. The trap again.

  • count(//*[local-name()='url'][not(*[local-name()='lastmod'])])on sitemap.xmlRun
    1

    Written namespace-aware: one URL is missing its lastmod.

  • boolean(//line)on order.xmlRun
    true
  • boolean(//nope)on order.xmlRun
    false
  • not(//nope)on order.xmlRun
    true

Run your own expression

What catches people out

  • An empty node-set is false; a node-set containing an empty element is true. Presence and content are different questions.
  • boolean('false') is true — it is a non-empty string, and XPath 1.0 has no boolean parsing.
  • not() takes a boolean, so not(@qty) asks whether the attribute is absent, not whether it is zero.

The sample documents

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

sitemap.xml
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <url><loc>https://example.com/</loc><lastmod>2026-01-01</lastmod></url>
  <url><loc>https://example.com/pricing</loc></url>
</urlset>
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.