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

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.

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.