[XML] Namespaces

Unlike HTML, XML lets you define your own elements (tags). XML namespaces are used for providing uniquely named elements and attributes in an XML document.

 

1. XML Namespace

An XML Namespace is a set of names in which all names are unique. Namespaces make it possible to give elements and attributes unique names and avoid conflicts between document definitions.

XML Namespace identifiers conform to the specific syntax for URI(Uniform Resource Identifier) references. URI has two general forms :

It does not matter which type of URI you choose – it’s a style choice. Many People prefer URL since URL is more familiar.

 

2. Declaring Namespaces

<!DOCTYPE xmlns:prefix='nsURI' >
<!DOCTYPE xmlns:food='http://www.food.com/food'>
<!DOCTYPE xmlns:html='http://www.w3c.org/TR/REC-html40/'>

 

3. Declaring a Namespace to an element

<prefix:element xmlns:prefix='nsURI' >
<food:Bread xmlns:food='http://www.food.com/food'>

 

4. Using Namespaces

<prefix:tagName> </prefix:tagName>
<food:h1> Pizza </food:h1>
<html:h1> Pizza </html:h1>

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s