XSD datatype
xs:QName
A namespace-qualified name — and the one type whose meaning depends on namespace declarations in scope, not just on the characters.
A QName is a prefix and a local name separated by a colon, or a local name alone. Its value is not the text: it is the pair of the namespace URI the prefix resolves to and the local name.
That makes it unlike every other datatype. The same literal means different things in different documents, and moving an element that contains a QName value into another document can silently change what it refers to — the prefix may not be declared there, or may be bound elsewhere.
- Lexical space
- An optional NCName prefix, a colon, and an NCName local part.
- Derives from
- Primitive type
- Category
- Other types
- Facets
- pattern, enumeration, whiteSpace, length, minLength, maxLength
What validates
Every literal below is put through the schema validator on each test run, against the schema at the foot of this page.
order
What does not
1st:xThe prefix must be an NCName, so it cannot start with a digit.
a:b:cOnly one colon is allowed.
undeclared:xThe prefix must be bound to a namespace in scope.
What catches people out
- The prefix must be declared where the value appears, not where the schema is. An unbound prefix is a validation error even though the characters look fine.
- Because the value depends on in-scope declarations, QName content does not survive being copied between documents.
- Comparing QNames as strings is wrong: two different prefixes bound to the same URI are equal.
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:QName"/>
</xs:schema>Related
- xs:NCNameAn XML name with no colon — the type of every element and attribute name, and of the local half of a QName.
- xs:NameAn XML name, which may contain a colon. Rarely the type you want — NCName usually is.
- xs:anyURIA URI reference — validated so loosely that almost any string passes, which makes it weaker than it looks.
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.