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 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.
<?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>Related
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.