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

    The prefix must be an NCName, so it cannot start with a digit.

  • a:b:c

    Only one colon is allowed.

  • undeclared:x

    The 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.

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