xmlns属性中名称空间的值 [英] Values for namespace in xmlns attribute

查看:126
本文介绍了xmlns属性中名称空间的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到下面的文档使用2个名称空间

I see the below document 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>

**

问题:-

名称空间是否有任何命名约定,或者应该仅仅是有效的http地址?

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

例如:-在下面的示例中,我给出了"test1"和"test2".有效吗?

For example:- In the below example I have given "test1" & "test2".Is it 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>

推荐答案

根据规范,名称空间名称" 可以是任何有效的URI -包括我们最熟悉的HTTP URL以及其他形式(如URN(统一资源名称)),它们以不同的方式进行管理方式.

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.

因此在您的示例中,http://test1.comhttp://test2.com是有效的URI,因此它们是有效的名称空间名称.

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

不过,本注释(摘自规范的本部分 )阐明了应如何选择URI :

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

名称空间名称应具有唯一性和持久性,以达到其预期目的.它不是可直接用于模式检索(如果存在)的目标.统一资源名称[RFC2141]是为实现这些目标而设计的语法示例.但是,应该注意,可以以实现这些相同目标的方式来管理普通URL.

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.

您可以保证(在合理程度上)创建URI的最明显方法是唯一 persistent 使用您要使用的域拥有.只要您对该域具有权限,其他人不太可能会选择相同的URL来具有不同的含义.此外,在该名称空间上寻找权限的任何人都将假定您(作为域的控制者)就是该权限.

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.

如果您拥有域user1050619.com,则可以使用名称空间名称http://user1050619.com/XMLNS/Test1http://user1050619.com/XMLNS/Test2

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

解析该URL不必产生任何有用的东西(或根本没有任何东西),但是通常的做法是在其中托管某种形式的文档-可以是机器可读的文档,例如DTD或模式定义,或解释该模式定义的元素的可读页面.或者,您可以将用户重定向到Rick Astley视频;)

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

这篇关于xmlns属性中名称空间的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆