</>
Skip to content
XML lessons (7/29)

XML — Namespaces

Why Namespaces?

When combining XML documents, element names may conflict:

<!-- Conflicting names -->
<table>
    <tr> <!-- Table row or table? -->
        <td>Data</td>
    </tr>
</table>

Namespace Syntax

<root xmlns:prefix="URI">
    <prefix:child>Content</prefix:child>
</root>

Default Namespace

<html xmlns="http://www.w3.org/1999/xhtml">
    <body>
        <p>Content</p>
    </body>
</html>

Practical Example

<?xml version="1.0" encoding="UTF-8"?>
<catalog xmlns:book="http://example.com/books"
         xmlns:person="http://example.com/people">
    <book:title>My Book</book:title>
    <person:name>John Doe</person:name>
</catalog>

Common Namespaces

PrefixURI
xmlnshttp://www.w3.org/2000/xmlns/
xmlhttp://www.w3.org/XML/1998/namespace
xshttp://www.w3.org/2001/XMLSchema
xslhttp://www.w3.org/1999/XSL/Transform

Mini Practice

  1. Create a namespace
  2. Use a default namespace
  3. Combine two namespaces
  4. Reference namespaced elements

Up Next

Continue with Encoding — character encoding in XML.

Related Topics

Frequently Asked Questions about Namespaces

What is Namespaces in XML?

Namespaces is a fundamental concept in XML. This lesson explains it step by step with clear examples, making it easy for beginners to understand.

How do I learn Namespaces?

Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn Namespaces.

Why is Namespaces important in XML?

Namespaces is essential for XML development. Understanding this concept will help you write better code and solve real-world problems more effectively.