Prefixed Namespace Declaration
In XML namespaces, the Prefixed Namespace Declaration method assigns a prefix to a namespace URI. This allows elements and attributes from that namespace to be identified with the specified prefix. Prefixed namespaces are especially beneficial when items from different namespaces appear in the same XML document.
Syntax:
<root xmlns:prefix="http://example.com/ns">
<prefix:child>Content</prefix:child>
</root>
Example: To demonsrtate the books catalog file structure in XML.
<?xml version="1.0" encoding="UTF-8"?>
<catalog
xmlns:bk="http://example.com/books"
xmlns:auth="http://example.com/authors">
<bk:book>
<bk:title>XML Basics</bk:title>
<auth:author>John Doe</auth:author>
</bk:book>
<bk:book>
<bk:title>Advanced XML</bk:title>
<auth:author>Jane Smith</auth:author>
</bk:book>
</catalog>
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