Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

XML Documents : Page 9

XML documents are similar to HTML documents. They contain information and markup tags that define the information, and are saved as ASCII text.


advertisement

Namespaces
Namespaces are a way of using elements from more than one DTD within the same XML document.

Sometimes you may be working with material that draws on several sets of element tags. For example, you might have an online store selling tropical fish and you'd like to use the <SOURCE> tag to identify both the geographic location from which each species comes and the wholesaler from whom you buy it. Namespaces are a way to do this.

An XML namespace is a collection of names, identified by a URI reference, which are used in XML documents as element types and attribute names. In practice, namespaces let you match a tag you are using with a particular set of tags.



In the beginning of your document (or at the start of a particular element of your document), you identify the namespaces you'll be using and where the tag information is located. Then, when you use the tag to identify an element in your document, you precede it with the appropriate namespace name.

Declaring Namespaces
At the beginning of your document, you'll want to identify the namespaces you are using in your document. This process is called declaring the namespace. In this example, you are creating a namespace called "sales." The URI for sales is the mythical fishworld.org/schema:

<document xmlns:SALES='http://fishworld.org/schema'>

Using Namespaces
When you use the tag to create the element that is defined in one of the namespaces, the namespace is the first part of the tag, like this:

<SALES: SOURCE>Fish-o-Rama Wholesalers and Suppliers to the Trade</SOURCE>

When you use your own tag you just use the tag name, like this:

<SOURCE>Mexico, Central America</SOURCE>

In January 1999, Namespaces became a W3C recommendation.





Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date