Namespaces guide
XML namespace prefix vs URI
Understand why prefixes are replaceable aliases, why namespace URIs are compared literally, and how expanded names keep documents interoperable.
7 min read · Updated 2026-08-21
The short answer
An XML namespace prefix is a document-local alias; the namespace URI is the identity. Two elements with different prefixes have the same expanded name when their prefixes bind to the same URI, while identical prefixes in different documents can name unrelated vocabularies.Compare expanded names rather than spellings
Processors identify a namespaced element by namespace URI plus local name. The prefix makes source readable and connects a qualified name to a declaration, but applications must not treat the chosen letters as the vocabulary identity.
<root xmlns:a="urn:example:catalog" xmlns:cat="urn:example:catalog">
<a:item/><cat:item/>
</root>Treat namespace URIs as exact identifiers
Namespace names are compared as strings. Changing http to https, adding a slash, changing case, or following a redirect produces a different name even when the URI looks related or resolves to the same page.
- Copy the namespace URI from the governing specification.
- Do not normalize schemes, slashes, or letter case.
- Do not require a namespace URI to return a document when fetched.
- Preserve unfamiliar namespace declarations during transformations.
Bind your own prefixes in XPath and XSLT
An XPath prefix is resolved from the evaluator's namespace map, not copied automatically from the source document. You may bind any convenient prefix to the correct URI and use it consistently in the expression.
Default namespaces apply to element names in XML source but not to unprefixed XPath 1.0 name tests, which is why a visible unprefixed element may still require a prefix in the query.
Prove the fix
- Look up a namespaceMatch an exact URI to its vocabulary and conventional prefix.
- Test a namespaced XPathBind your own query prefix to the document's namespace URI.
- Read namespace terminologyReview default namespaces, declarations, prefixes, and expanded names.
Related guides
- Why XPath matches nothing in a default namespaceThe XPath 1.0 namespace rule behind an empty //loc result, with the prefix-bound solution and the local-name fallback.
- XPath local-name() vs namespace prefixesChoose explicit namespace bindings for precise XPath, and reserve local-name() fallbacks for deliberate namespace-agnostic inspection.
- How to fix a duplicate XML attributeFind the repeated expanded attribute name, decide which value owns the field, and fix generators that merge attribute collections unsafely.
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.