You are on page 1of 1

XML Namespaces

 It is possible to have two document types have elements with same


name, but different meanings and semantics.
 Using XML namespaces we can differentiate elements and attributes of
different XML document types from each other when combining them
together into other documents or processing multiple documents
simultaneously.
 XML Namespaces provide a method to avoid element name conflicts.
 In XML, element names are defined by the developer. This often
results in a conflict when trying to mix XML documents from different
XML applications.

Eg: <student>
<BTECH>
<course> Computer Science </course>
<age> 22 </age>
</BTECH>
<MTECH>
<course> DataScience </course>
<age> 24 </age>
</MTECH>
</student>

Here would be a name conflict for <course> and <age>, but the elements
have different content and meaning.

Name conflicts in XML can easily be avoided using a name prefix.

<student xmlns:ug="http://www.w3.org/2001/XMLSchema"
xmlns:pg="http://www.w3.org/2001/XMLSchema" >
<BTECH>
<ug:course> Computer Science </ug:course>
<ug:age> 22 </ug:age>
</BTECH>
<MTECH>
<pg:course> DataScience </pg:course>
<pg:age> 24 </pg:age>
</MTECH>
</student>

You might also like