Creating an XML namespace without a domain
Usually tutorials tell you to use your own domain name when making a new XML namespace. Not everybody owns a domain, it costs money, and the site might be unrelated to the purpose that you are using the XML for.
What is a good alternative?
In this answer, the example just has some_identifier
, however Wikipedia says it is a URI. URIs can be URLs or URNs.
URLs can provide a link to the schema, however the primary purpose of the namespace is to be a unique identifier, so a URN fits better.
How do you generate a unique identifier? UUIDs are good for identifiers, so I searched and there is even an example on W3C:
<?xml:namespace ns='urn:uuid:C4ED1820-6207-11d1-A29F-00AA00C14882/'
src='http://www.w3.org' prefix='w3c' ?>
Why don't people use UUIDs more often? What are the disadvantages of UUID namespace or advantages of a domain-based namespace? If your domain expires you might lose it and have to change all your namespaces.
There is no connection except by happenstance between a DNS domain name and an XML namespace.
If you have a DNS domain name and want to use it in your XML namespace, you can. If you do not have a DNS domain name or do not want to use it in your XML namespace, that is fine too.
UUIDs are not typically used for XML namespaces because they are not very meaningful - similar to typically using host & domain names over IP addresses.
If you want a readable, globally unique identifier that only requires you to declare ownership of a domain or email address at a point in time, you could use a tag URI. For example:
tag:user@example.com,2007-11-02:Tag_URI
A urn:uuid
would be perfectly valid, but sometimes identifiers with more structure can be more discoverable, or allow for associating related namespaces.
This question is a similar problem, except for Java package names. The Java Specification suggests the domain convention, but it is not mandatory. Their choice is explained as follows:
The suggested convention for generating unique package names is merely a way to piggyback a package naming convention on top of an existing, widely known unique name registry instead of having to create a separate registry for package names.
Following are some options and their main advantages and disadvantages.
UUID
Advantages:
Disadvantages:
URL
Advantages:
Disadvantages:
Advantages:
Disadvantages:
Tag URIs
From Joe's answer.
Advantages:
Disadvantages:
Anything
Advantages:
Disadvantages:
Conclusion
I think the best solution in the end is a UUID plus maybe a canonical project name (you may run into problems if you want to change the name). Domains/emails aren't relevant to a project and are just a way to provide uniqueness, which is obsoleted by UUIDs.
链接地址: http://www.djcxy.com/p/70136.html上一篇: 适当的URN命名空间现在是X.
下一篇: 创建没有域的XML名称空间