Skip to main content
XMLDir

Search 261 pages — tools, formats, elements, namespaces, XPath, datatypes, glossary, parse errors, schema errors, use cases, blog and product.

XSD datatype

xs:boolean

Exactly four literals: true, false, 1 and 0. Not 'yes', not 'True', not 'on'.

xs:boolean has a lexical space of precisely four strings. '1' and '0' are the numeric spellings of true and false, kept for compatibility with older data formats.

Case matters. 'True' is not a valid xs:boolean, which catches anything serialised by a language that capitalises its booleans — Python being the obvious one.

Lexical space
One of: true, false, 1, 0.
Derives from
Primitive type
Category
Other types
Facets
pattern, whiteSpace

What validates

Every literal below is put through the schema validator on each test run, against the schema at the foot of this page.

  • true
  • false
  • 1
  • 0

What does not

  • True

    Case-sensitive; only lowercase is valid.

  • yes

    Not one of the four literals.

  • TRUE

    Case-sensitive.

  • (the empty string)

    Empty is not a boolean.

What catches people out

  • 'True' from a Python serialiser fails. So does 'YES' from a spreadsheet.
  • There is no enumeration facet on xs:boolean — the value space has only two members already.
  • '0' and 'false' are both false and are distinct literals, so a string comparison of the raw text is not a boolean comparison.

The schema used

This is the exact schema the literals above are validated against. Paste it into the validator with one of them to see the result yourself.

schema.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="v" type="xs:boolean"/>
</xs:schema>

Open the XSD validator

Related

All 29 datatypes and facets

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.