XML Namespaces Explained
Advertisement
Ad
What are XML Namespaces?
Namespaces prevent naming conflicts when combining XML from different sources. They qualify element names with a unique prefix tied to a URI.
The Problem
<!-- Two "table" elements with different meanings -->
<table><tr><td>Cell</td></tr></table> <!-- HTML table -->
<table><name>Coffee Table</name></table> <!-- furniture -->
The Solution: Prefixes
<root xmlns:h="http://www.w3.org/1999/xhtml"
xmlns:f="https://furniture.example.com">
<h:table><h:tr><h:td>Cell</h:td></h:tr></h:table>
<f:table><f:name>Coffee Table</f:name></f:table>
</root>
Default Namespace
<book xmlns="https://books.example.com">
<title>No prefix needed here</title>
</book>
FAQs
Is the URI a real web address?
No — it's just a unique identifier. It doesn't need to resolve to anything. More in our XML guides.
When do I need namespaces?
When mixing vocabularies (e.g. SVG inside XHTML, or SOAP envelopes).
