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:ID, xs:IDREF and xs:IDREFS

Document-scoped unique identifiers and references to them — with uniqueness enforced across the whole document, not per element.

xs:ID derives from xs:NCName, so it inherits every naming restriction: no leading digit, no colon, no spaces. Its value must be unique across the entire document, and each element may carry at most one.

xs:IDREF must match an existing ID somewhere in the same document, and xs:IDREFS is a whitespace-separated list of them. That cross-reference check is one of the few things XSD validates beyond a single value.

Lexical space
An NCName, unique within the document.
Derives from
xs:NCName
Category
Other types
Facets
length, minLength, maxLength, pattern, enumeration, 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.

  • A-1001
  • _x
  • line.1

What does not

  • 1st

    Inherits NCName's rule against a leading digit.

  • a b

    No whitespace in an NCName.

  • soap:x

    No colons.

What catches people out

  • Uniqueness is document-wide, so two different element types cannot share an ID value.
  • An IDREF that points at nothing is a validation error, which is easy to hit when validating a fragment rather than a whole document.
  • Because it derives from NCName, a numeric key like '1001' cannot be an xs:ID. Prefix it.

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