Search /
Docfinder:
Advanced search  |  Help  |  Site map
RESEARCH CENTERS
SITE RESOURCES
Click for Layer 8! No, really, click NOW!
Networking for Small Business
TODAY'S NEWS
iPhone 5 rumor rollup for the week ending Feb. 10
Forget Public Cloud or Private Cloud, It's All About Hyper-Hybrid
Apple passes HP as largest tech company
How to get the IRS' attention: Forge nearly $8 million in tax returns, steal identities
Much of Western U.S. is a 3G wasteland, says FCC
How the Phoenix Suns basketball team takes on social media attacks
Microsoft details Windows 8 for ARM devices
Resume Makeover: How an Information Security Professional Can Target CSO Jobs
Blogger exposes major Google Wallet security flaw
Web app lets enterprise set security, sharing for Google Apps users
Cloudscaling to offer OpenStack private cloud platform
Macs take on the enterprise
Valentine's Day Patch Tuesday: Microsoft to issue 9 patches, 4 critical
Mobile World Congress sneak peek: Quad-core smartphones, Ice Cream Sandwich & more
/

Making a namespace for yourself

Related linksToday's breaking news
Send to a friendFeedback

Gearhead archive

Last week we delved into SOAP and casually tossed out the term "namespace." While we didn't make much of it at the time, the fact is that namespaces are a crucial component of XML and, by extension, of SOAP and Web services.

You see, one of the problems of XML is its tremendous flexibility. For example, in the case of library data, the tag "name" could mean an author's name or a publisher's name, depending on the intention of the XML data set it appears in. One library's XML description of a book might be:

<libraryitem>
<title>The Truth Machine</title>
<publisher>
<name>Del Rey Books</name>
</publisher>
<author>
<name>James L. Halperin</name>
</author>
</libraryitem>

If you don't know the structure of a libraryitem, handing the XML data to a computer is likely to cause problems with understanding the attribute name.

So to make our intentions clear, we'll group the tags (properly called "elements") we use in an XML document under a name that provides, in effect, a category for all the tags under it. To define the architecture of the elements, we'll create a definition of the category using a Document Type Definition (DTD) or the more powerful XML Schema (XSD) specification.

An XSD schema is easier to understand than a DTD because it is written in XML. It also is far more comprehensive in its ability to characterize how the content of an XML file is structured. We'll visit XSD next week, as it is a huge topic.

So let us declare a namespace:

<vii:libraryitem xmlns:vii = "http://www.gibbs.com/demoschema">

What this defines is where the definition of the namespace "vii" can be found and that the element libraryitem is part of that namespace.

You may have noticed that the URL for the namespace definition points to a subdirectory that may contain a DTD or XSD. If there is no definition file, the result is merely declaring a unique identity, in this case, for the namespace "vii."

Any reference to another namespace also named "vii" but linked to a different URL would define a different namespace. Now, although a single XML document can reference multiple namespaces, duplicate names for namespace are not supported. So here's our file with all of the elements explicitly defined as belonging to the "vii" namespace:

<vii:libraryitem xmlns:vii = "http://www.gibbs.com/demoschema>
<vii:title>The Truth Machine</vii:title>
<vii:publisher>
<vii:name>Del Rey Books</vii:name>
</vii:publisher>
<vii:author>
<vii:name>James L. Halperin</vii:name>
</vii:author>
<vii:libraryitem>

As long as the only namespace in use is "vii" we could omit all references to it in all the elements between the first and last line (in other words, except for the first and last line, the content would be identical with the first example we showed).

Of course, if we had two or more schemas we could reference multiple namespaces with different names. Thus:

<libraryitem
xmlns:vii = "http://www.gibbs.com/demoschema
xmlns:gac = "http://www.vitallyimportantinformation.com/schema>

So if we refer to elements such as "vii:name" and "gac:name" it's obvious the schema for each use of "name" is different.

Remember that an XML tag is made up of:

<element_name attribute_name = "attribute_value">
element_value
</tag_name>

We even can define attributes as belonging to specific namespaces, different from the namespaces of the elements that possess the attributes, thus:

<vii:temperature gac:unit="Celsius">36</vii:temperature>

Next week, XSD. Whoopee!

RELATED LINKS

Comments and suggestions to gh@gibbs.com.

Gibbs Forum
The place to discuss Gibbs's columns.

Check out this week's edition of

Backspin for more musings from Gibbs.

Web services research page
Information and background on emerging standards such as XML, SOAP, WSDL, UDDI and more.

Web Applications newsletter
Stay current on new products and features, and learn how to get the most out of your apps.

Web services quandary
Tomorrow's business-to-business e-comm requires navigating the maze of conflicting Web services standards.
Network World Electronic Commerce Issue, 02/18/02.

Assembling a top-of-the-line Web services model
Ford Credit wins Network World's 2002 E-comm Innovator Award with an open-standards infrastructure that saves the company carloads of money.
Network World Electronic Commerce Issue, 02/18/02.


NWFusion offers more than 40 FREE technology-specific email newsletters in key network technology areas such as NSM, VPNs, Convergence, Security and more.
Click here to sign up!
New Event - WANs: Optimizing Your Network Now.
Hear from the experts about the innovations that are already starting to shake up the WAN world. Free Network World Technology Tour and Expo in Dallas, San Francisco, Washington DC, and New York.
Attend FREE
Your FREE Network World subscription will also include breaking news and information on wireless, storage, infrastructure, carriers and SPs, enterprise applications, videoconferencing, plus product reviews, technology insiders, management surveys and technology updates - GET IT NOW.