Skip to main content

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

XSD datatype

xs:negativeInteger

An integer strictly below zero. Zero, including -0, is rejected.

xs:negativeInteger fixes maxInclusive at -1. It is unbounded below and differs from nonPositiveInteger at exactly one value: zero.

The restriction applies to the value, so -0 is zero and fails even though its lexical form begins with a minus sign.

Lexical space
A signed integer whose value is -1 or less.
Derives from
xs:nonPositiveInteger
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.

  • -1
  • -42
  • -999999999999999999999

What does not

  • 0

    Zero is not negative.

  • -0

    The value of -0 is zero.

  • 1

    Positive values are excluded.

What catches people out

  • -0 fails because facets constrain the value, not the spelling.
  • There is no lower bound.
  • Use nonPositiveInteger when zero is a meaningful boundary value.

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:negativeInteger"/>
</xs:schema>

Open the XSD validator

Related

All 39 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.