Names and namespaces
Namespace prefix
The short NCName bound to a namespace URI by an xmlns:prefix declaration, used before a colon to qualify names.
A prefix is a local abbreviation with no meaning of its own. It is in scope on the element that declares it and its descendants, it can be rebound deeper in the tree, and the same document can use different prefixes for the same URI in different places without changing what it means.
That makes prefixes cosmetic to a processor and load-bearing to a reader, which is a bad combination. Conventional prefixes — atom:, dc:, itunes: — are conventions only; nothing enforces them, and a document is free to use any prefix it declares.
- Defined in
- Namespaces in XML 1.0 §3
- Category
- Names and namespaces
- Also written
- prefix, xmlns:foo
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.
An undeclared prefix is not a well-formedness error — XML 1.0 and Namespaces are separate specifications.
document.xml <a:x>hi</a:x>What the engine returns
Well-formed.Declaring the same prefix twice on one element is a well-formedness error.
document.xml <x xmlns:a="urn:1" xmlns:a="urn:2"/>What the engine returns
Attribute xmlns:a redefined (line 1)
What catches people out
- An undeclared prefix parses cleanly. Namespace correctness is a separate check, and many tools never run it.
- The prefix xml is bound to its namespace permanently and needs no declaration; the prefix xmlns cannot be bound at all.
- Rebinding a prefix deeper in a document is legal and confusing. Two elements with the same tag text can be in different namespaces.
Where it bites
A definition on its own is trivia. These are the pages where this term decides whether a document works.
- NamespacesThe reserved xml: namespaceThe one prefix that is always bound, and what xml:lang and xml:space mean.
- ToolsXML validatorReports undeclared prefixes separately from parse errors, because they are a different kind of wrong.
- XPathname()Returns the prefixed name as written, which is what makes it unreliable for matching.
Related terms
- NamespaceA URI that qualifies element and attribute names, so identically-named elements from different vocabularies can coexist in one document.
- Default namespaceThe namespace declared by a bare xmlns="…", which applies to unprefixed element names on that element and its descendants.
- QNameA qualified name: an optional namespace prefix, a colon, and a local name — the form every element and attribute name takes in a namespaced document.
- Expanded nameThe pair of namespace URI and local name that a QName resolves to — what processors actually compare when they match a name.
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.