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

2020-07-08 07:09发布

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?

标签: wpf xml
5条回答
够拽才男人
2楼-- · 2020-07-08 07:33

From this article at W3Schools:

"The namespace URI is not used by the parser to look up information. The purpose is to give the namespace a unique name. However, often companies use the namespace as a pointer to a web page containing namespace information. Try to go to http://www.w3.org/TR/html4/."

查看更多
我命由我不由天
3楼-- · 2020-07-08 07:38

It is a reliable way to create a readable globally unique identifier. It may or may not be to a valid URL with more information.

查看更多
唯我独甜
4楼-- · 2020-07-08 07:40

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 e.g. 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
查看更多
趁早两清
5楼-- · 2020-07-08 07:54

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.

查看更多
Fickle 薄情
6楼-- · 2020-07-08 07:57

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 :)

查看更多
登录 后发表回答