Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are URLs in XML namespaces?

Take this line as just one example:

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
</configuration>

Some brief research has taught me that nothing necessarily has to be hosted at that URL. Therefore, if it's just a reference to a namespace contained in a local assembly, why use URLs instead of regular namespaces like the ones typically used by .NET (System.Data, for example)?

like image 354
oscilatingcretin Avatar asked Apr 22 '11 17:04

oscilatingcretin


People also ask

What is URI in XML namespace?

A Uniform Resource Identifier (URI) is a string of characters which identifies an Internet Resource. The most common URI is the Uniform Resource Locator (URL) which identifies an Internet domain address. Another, not so common type of URI is the Uniform Resource Name (URN).

What is the benefit of using XML namespace?

Advantages of Namespaces in XMLIt avoids duplicate element names and attributes defined in an XML document where the XML element defined in one organization product may conflict with the other.

Does XML need a namespace?

This information is needed because some XML vocabularies allow qualified names (containing namespace prefixes) to appear in the content of elements or attributes, as well as in their names.

What is the purpose of using a default namespace in an XML file?

When you use multiple namespaces in an XML document, you can define one namespace as the default namespace to create a cleaner looking document. The default namespace is declared in the root element and applies to all unqualified elements in the document. Default namespaces apply to elements only, not to attributes.


2 Answers

When you ask why a standard is the way it is, there are two possible interpretations of your question: (a) what are the perceived benefits of the design choice that was made, and (b) what was the historical sequence of events that led to this design being adopted over other designs.

Clearly, using HTTP-like URIs gives uniqueness. But that could also have been achieved in other ways, for example by inventing a new URI scheme. I think that if you trace the arguments that were made at the time, you will find that many of the people advocating the use of HTTP-style URIs were also advocating that namespace URIs should be dereferencable, perhaps to a schema or to some other kind of document. Indeed, it's W3C policy for its own namespaces that there is always a document that can be retrieved when you type the namespace URI into a browser, and that it should tell you something useful about the namespace.

So I suspect the fact that we use URIs that look deferenceable but don't define any semantics for what happens when they are dereferenced is in fact the result a committee compromise between two or more opposing camps. But you'd have to do some proper historical research to confirm that.

like image 163
Michael Kay Avatar answered Oct 11 '22 19:10

Michael Kay


It's just a convention. URIs (which is what they are, not really URLs) are a convenient and globally-familiar way of identifying resources. On the other hand, .NET-style identifiers are familiar and recognisable to, well, .NET developers - there's rather more to XML than .NET.

like image 30
skaffman Avatar answered Oct 11 '22 21:10

skaffman