Values for namespace in xmlns attribute

前端 未结 2 978
北恋
北恋 2021-01-22 08:29

I see the below document using 2 namespaces

**



  
    Apple         


        
相关标签:
2条回答
  • 2021-01-22 08:54

    The namespace URI is not used by the parser to look up information.

    I think it should be sufficient for the URIs for the h and f namespaces you mentioned to simply be unique, valid URIs. In most examples, I've seen http used as the scheme name.

    So, a perfectly valid namespace (that does not map to a valid website) could be:

    xmlns:foo="http://my.example.ns"
    
    0 讨论(0)
  • 2021-01-22 09:10

    According to the specification, a "namespace name" can be any valid URI - that includes the HTTP URLs we are most familiar with, and other forms such as URNs (Uniform Resource Names), which are managed in different ways.

    So in your example http://test1.com and http://test2.com are valid URIs, so they are valid namespace names.

    However, this note (from this section of the spec) clarifies how a URI should be chosen:

    The namespace name, to serve its intended purpose, SHOULD have the characteristics of uniqueness and persistence. It is not a goal that it be directly usable for retrieval of a schema (if any exists). Uniform Resource Names [RFC2141] is an example of a syntax that is designed with these goals in mind. However, it should be noted that ordinary URLs can be managed in such a way as to achieve these same goals.

    The most obvious way of creating a URI which you can guarantee (to a reasonable degree) will be unique and persistent is to use a domain which you own. As long as you have authority over that domain, it is unlikely that someone else will choose the same URL to have a different meaning. Furthermore, anyone looking for an authority on that namespace will assume that you, as the controller of the domain, are that authority.

    If you owned the domain user1050619.com, you could therefore use the namespace names http://user1050619.com/XMLNS/Test1 and http://user1050619.com/XMLNS/Test2

    It is not necessary for resolving that URL to result in anything useful (or anything at all), but it is common practice to host some form of documentation there - either a machine-readable document like a DTD or Schema Definition, or a human-readable page explaining the elements defined by that schema. Alternatively, you could redirect the user to a Rick Astley video ;)

    0 讨论(0)
提交回复
热议问题