XML
Beginner
1 min read
Default and Prefixed Namespace Declarations
Example
<?xml version="1.0" encoding="UTF-8"?>
<!-- Default namespace declared on root -->
<root xmlns="http://example.com/default"
xmlns:meta="http://example.com/meta"
xmlns:html="http://www.w3.org/1999/xhtml">
<!-- 'child' is in default namespace (example.com/default) -->
<child>
<!-- Unprefixed attributes are in NO namespace -->
<item id="1" meta:version="2.0">text</item>
<!--
id → null namespace (NOT example.com/default)
meta:version → http://example.com/meta
-->
</child>
<!-- Override default namespace locally -->
<section xmlns="http://example.com/other">
<!-- 'para' is in example.com/other -->
<para>Different namespace here.</para>
</section>
<!-- Undeclare default namespace: back to no namespace -->
<raw xmlns="">
<data>No namespace at all.</data>
</raw>
<!-- Mixed: XHTML fragment embedded -->
<html:div>
<html:p>This paragraph is in the XHTML namespace.</html:p>
</html:div>
</root>