Default Namespace Declaration
Default Namespace Declaration in XML namespaces assigns a default namespace to all unprefixed components inside a given scope. This signifies that elements without a prefix are presumed from the given namespace. The “xmlns” element is used to declare the default namespace.
Syntax:
<root xmlns="http://example.com/ns">
<child>Content</child>
</root>
Example: To demonstrate the XML library catalog file structure in XML.
<?xml version="1.0" encoding="UTF-8"?>
<library
xmlns="http://example.com/library">
<book>
<title>XML Basics</title>
<author>John Doe</author>
</book>
<book>
<title>Advanced XML</title>
<author>Jane Smith</author>
</book>
</library>
Output:
XML Namespaces
XML namespaces prevent naming conflicts between elements and attributes in XML documents, especially when various XML vocabularies are joined or elements with the same name come from different sources.
Table of Content
- Default Namespace Declaration
- Prefixed Namespace Declaration