Java Reference
In-Depth Information
This Java code creates a QName that looks like this in XML:
<StockQuoteSoap xmlns="http://www.webserviceX.NET/">
NOTE
An interesting thing about QName s, should you ever need to compare two instances, is that the prefix
is not used by the equals or hashcode methods. It seems obvious why this would be the case: the
prefix is user-defined and incidental to the current document; it doesn't really distinguish two names.
The third and final constructor allows you to create a QName with a local part only.
URIs, URLs, and URNs in namespaces
QName documentation refers to “URI references” as the value allowed for the namespaceURI
field. The Uniform Resource Identifier is the superset of the other two. URLs are, obviously,
locators: they identify a place, or imply a physical resource. These are by far the most com-
monly used as namespaces for a variety of reasons, not the least of which is their popularity
due to the ubiquity of the Web. In addition, they are hierarchical in structure, they are com-
monly understood, and companies that create things that need namespaces generally have a
domain name that can be used to readily differentiate their namespaces from anyone else's
(like Java packages).
But for the more, um, academically inclined among us, there are certain disadvantages to us-
ing URLs. First, they specify a protocol, which is out of place in a namespace; also, they imply
that there is a physical resource associated with the element that the namespace marks (which
is, of course, their purpose).
So some people have turned to using URNs, or Uniform Resource Names. While these carry
a syntax similar to URLs and are still usually hierarchical in structure (depending on the au-
thor), they also have the advantages of appearing purely as a namespace and implying no other
purpose or object. URNs also allow you to maintain the hierarchical structure we love about
URLs.
URNs have this basic format: "urn:" . For example:
<Namespace Identifier> ":" <Namespace Specific String>
These are often seen specified as a colon-separated list, preceded by “urn”, sometimes with
version information at the end, as follows:
<e:getQuote xmlns:e="urn:example:quotes:2:0">
Search WWH ::




Custom Search