Skip to main content
XMLDir

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

Names and namespaces

QName

A qualified name: an optional namespace prefix, a colon, and a local name — the form every element and attribute name takes in a namespaced document.

A QName is what you write. What the processor compares is the expanded name it resolves to: the namespace URI the prefix is bound to, plus the local name. Two documents using different prefixes for the same URI contain the same elements, and a document reusing one prefix for two URIs in different scopes contains different ones.

As a datatype, xs:QName is unusual and worth treating with suspicion. Validating a value against it requires the prefix to be in scope at that point in the document, so a schema-valid value in one document is invalid in another that spells the prefix differently.

Defined in
Namespaces in XML 1.0 §4
Category
Names and namespaces
Also written
qualified name, prefix:local

Shown, not asserted

All 2 claims are executed on every test run, against the same engines the tools use. If the behaviour changes, the test fails rather than this page quietly becoming wrong.

  • xs:QName rejects a prefixed value whose prefix is not declared in scope.

    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>
    value
    a:b

    What the engine returns

    Invalid as xs:QName.
  • Which prefix a document chose does not matter: what is compared is the namespace URI.

    document.xml
    <r xmlns:z="urn:a"><z:c/></r>
    expression
    count(//*[namespace-uri()='urn:a'])

    What the engine returns

    1

What catches people out

  • A QName with no prefix is still a QName. In a document with a default namespace it is in that namespace; otherwise it is in none.
  • xs:QName values in element content — as in XSD's own type attribute — depend on prefixes declared in the instance document, which is why they survive copy-paste so badly.
  • A colon is legal in an xs:Name but not in an xs:NCName. That difference is exactly what separates a QName's two halves.

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.