Values ​​for namespace in xmlns attribute

I see the document below using 2 namespaces

**

<root> <h:table xmlns:h="http://www.w3.org/TR/html4/"> <h:tr> <h:td>Apples</h:td> <h:td>Bananas</h:td> </h:tr> </h:table> <f:table xmlns:f="http://www.w3schools.com/furniture"> <f:name>African Coffee Table</f:name> <f:width>80</f:width> <f:length>120</f:length> </f:table> </root> 

**

Question: -

Is there any naming convention for the namespace or should only be a valid http address?

For example: - In the example below, I gave "test1" and "test2". Is it really valid?

 <root> <h:table xmlns:h="http://test1.com"> <h:tr> <h:td>Apples</h:td> <h:td>Bananas</h:td> </h:tr> </h:table> <f:table xmlns:f="http://test2.com"> <f:name>African Coffee Table</f:name> <f:width>80</f:width> <f:length>120</f:length> </f:table> </root> 
+2
xml namespaces
source share
2 answers

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

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

However, this note (from this section of the specification ) explains how to choose a URI:

A namespace name intended for its intended use SHOULD have characteristics of uniqueness and perseverance. It is impractical to use it to search for a circuit (if one 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 regular URLs can be managed in such a way as to achieve the same goals.

The most obvious way to create a URI that you can guarantee (to a reasonable extent) will be unique and permanent is to use the domain that you have . As long as you have authority over this domain, it is unlikely that anyone else will choose the same URL to have a different value. Also, anyone looking for authority in this namespace will assume that you, as a domain controller, are that authority.

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

It is not necessary to resolve this URL as a result of anything useful (or anything at all), but it is common practice to place some form of documentation there β€” either a machine-readable document, such as a DTD or schema definition, or human-readable A page explaining the elements identified by this diagram. Alternatively, you can redirect the user to a Rick Astley video;)

0
source share

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

I think this should be enough so that the URIs for the h and f names he names are simply unique, valid URIs. In most examples, I saw that http is used as the name of the scheme.

Thus, a perfectly valid namespace (which does not map to a valid website) could be:

 xmlns:foo="http://my.example.ns" 
0
source share

All Articles