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:nonNegativeInteger

An integer of 0 or more. The right type for counts, where zero is a real answer.

xs:nonNegativeInteger allows zero and everything above it. It is the type for quantities, counts and sizes, where zero is a legitimate value rather than an error.

xs:unsignedInt and friends are the bounded versions; this one is unbounded.

Lexical space
Optional plus sign, then digits, with a value of 0 or greater.
Derives from
xs:integer
Category
Numeric types
Facets
minInclusive, maxInclusive, minExclusive, maxExclusive, pattern, enumeration, whiteSpace, totalDigits, fractionDigits

What validates

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

  • 0
  • 1
  • +0
  • 42
  • -0

What does not

  • -1

    Negative values are excluded.

  • 1.0

    A decimal point is not allowed on an integer type.

What catches people out

  • '-0' validates, because its value is zero. The lexical form is allowed even though it looks negative.
  • Unbounded above. Use xs:unsignedInt for a 32-bit ceiling.

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:nonNegativeInteger"/>
</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.