XML Namespaces

XML Namespace used when we have conflicts with XML elements names. It helps to avoid conflicts. We can say, it provides a way where we make unique names for XML elements.

We can create group for XML elements and their attributes by using Namespaces. Programmers generally create element and their name so they might create elements in such a way where it get conflict so to void that, they should use Namespaces. If you would like to use same name for elements, you may use prefix and that will also works fine.


<element xmlns:name = " YOUR URL">


<?element xmlns = " YOUR URL">

You must declare attributes like xmlns or xmlns:

Name is prefix which you can use to define namespace.

You must use URL which is called identifier for Namespaces.

URI: Uniform Resource Identifier:

URI is text values which is used to identify resources. URL(Uniform Resource Locator) is widely used for URI to identify domain or website name.


<?xml version="1.0" encoding="UTF-8"?>
<q:question xmlns:q="https://www.stoodq.com/question">
<q:title>What is xml?</q:title>
<q:user>John Smith</q:user>
<q:date>July 25 2018</q:date>

You will learn more about namespaces in XSLT section.