Why do XML Namespaces usually start with http://...?

For example, the WPF namespace is: xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

If I define my own namespace, should it also start with http? Isn't http misleading ?


The W3C Document defining XML Namespaces says (quoting) :

Definition: An XML namespace is identified by a URI reference [RFC3986]

And RFC 3986 says (quoting) :

1.1.1. Generic Syntax

Each URI begins with a scheme name, as defined in Section 3.1, that
refers to a specification for assigning identifiers within that
scheme.

So I guess using http:// is what's closest to the standard -- as HTTP is the most common scheme used on the net.

In addition, as there can be only one owner for a domain name, it allows each company to use it's URL in its namespaces.


Namespaces doesn't have any meaning in their value, except for that value to be unique to avoid nameclashing. This is why you see a lot of companies putting in the URL for their own website as the namespace. URLs serve the same purpose, to be unique. Over the years it's just become good practice to use an URL, because if everyone does that, no nameclashing should occur :)


Another common way instead of using a URL starting with http:// is to use a Uniform Resource Name whose format is defined by RFC2141.

Such namespace identifiers are eg used by ODF (OpenDocument Format):

urn:oasis:names:tc:opendocument:xmlns:office:1.0
urn:oasis:names:tc:opendocument:xmlns:style:1.0
urn:oasis:names:tc:opendocument:xmlns:text:1.0
链接地址: http://www.djcxy.com/p/34556.html

上一篇: 工具在哪里?

下一篇: 为什么XML命名空间通常以http:// ...开头?