在 DTD 中,为什么将命名空间作为 URL 给出? [英] In DTDs, why are namespaces given as a URL?

查看:19
本文介绍了在 DTD 中,为什么将命名空间作为 URL 给出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

显然,HTML 和 XML 页面中 xmlns 之后的命名空间 URL 是没有意义的.一直以来,我虽然在这些地址上实际上有命名空间......

Apparently, the namespace URL that follows xmlns in HTML and XML pages are meaningless. And all this time I though there actually were namespaces at those addresses...

当我第一次阅读/听说命名空间时,我想象在所提供的 URL 中有一些大文件,其中包含可以在文档实例中使用的所有有效名称"的列表.我才知道我想错了.

When I first read/heard about namespaces, I imagined there some large files at the URLs provided that contained a list of all the valid 'names' that could be used in instances of the document. I've come to learn I imagined wrong.

但如果 URL 完全没用,那么命名空间的意义何在?如果某个东西实际上并不存在于任何地方,你怎么知道它是否属于一个命名空间?当我指定一个命名空间"时我真的在做什么吗??

But if the URL is totally useless, what exactly is the point of a namespace? How do you know if something belongs to a namespace if it doesn't actually exist anywhere? When I'm specifying a "namespace" am I actually doing anything??

在我看来,这在任何意义上都是完全任意的.

It sounds to me like it's totally arbitrary in every sense of the word.

推荐答案

命名空间名称在 XML 中的基本功能是提供一个唯一标识符,让需要处理 XML 文档的软件或人员知道是否遇到了特定元素在输入中是或不是它们负责处理的元素之一.假设您是一个专门用于处理名为blort"的元素并将结果显示在用户显示器区域的软件.每当您在输入中看到名为blort"的元素时,您必须确定您在输入中看到的blort"元素是您应该处理的blort"元素,还是另一个具有相同名称但不同的结构或含义.没有命名空间,您无法确定.

The essential function of a namespace name in XML is to provide a unique identifier which allows software or people who need to process XML documents to know whether a particular element encountered in the input is, or is not, one of the elements they are responsible for processing. Suppose you are a specialized piece of software designed to process elements named 'blort' and display the results in an area of the user's display. Whenever you see an element named 'blort' in the input, you must decide whether the 'blort' element you are seeing in the input is the 'blort' element you are supposed to work on, or another element with the same name but a different structure or meaning. Without namespaces, you cannot know for certain.

如果满足以下条件,则可以解决此问题:

This problem can be solved if:

  • 每个发明 XML 词汇表(并且关心避免名称冲突)的人都会为他们的词汇表选择一个唯一的名称.出于各种历史、技术和风格原因,我们将此名称称为命名空间名称".

  • Everyone who invents an XML vocabulary (and cares about avoiding name conflicts) chooses a unique name for their vocabulary. For a variety of historical, technical, and stylistic reasons, we call this name a 'namespace name'.

我们找到了一些方法让 XML 元素或属性的全名包含命名空间名称.这就是一些规范所称的扩展名称":由命名空间名称和本地名称"组成的一对.

We find some way to make the full name of an XML element or attribute include the namespace name. This is what some specs call the 'expanded name': a pair consisting of the namespace name and the 'local name'.

只要满足第三个标准,您现在就可以将您设计处理的词汇表中的blort"与您可能找到的任何其他blort"区分开来(只需查看它们的扩展名称!):

You can now distinguish between the 'blort' in the vocabulary you are designed to handle from any other 'blort' you may find (just look at their expanded names!), as long as the third criterion is met:

  • 没有两个 XML 词汇表的发明者为其词汇表选择相同的命名空间名称.

确保任意标识符唯一性的常用方法是拥有某种中央注册表.然而,中央注册中心很难构建和维护,XML 名称空间使用 URI 作为一种捎带最成功的注册机构之一的方式:在互联网核心维护域名系统的机构.只要命名空间名称的发明者遵循仅在他们拥有或控制的部分URI空间中分配命名空间名称的基本规则,不同的发明者就永远不会选择相同的命名空间名称.

The usual way to ensure the uniqueness of arbitrary identifiers is to have some sort of central registry. Central registries, however, are difficult to build and maintain, and XML namespaces use URIs as a way of piggy-backing on one of the most successful of registration authorities: the one that maintains the domain-name system at the heart of the Internet. As long as inventors of namespace names follow the basic rule of assigning namespace names only in the part of URI space they own or control, different inventors will never choose the same namespace name.

使用 URI 作为命名空间名称还有一个很好的特性,即命名空间的定义者可以将人类和机器可读的命名空间文档放在命名空间 URI 中.一些权威机构推荐这是一种良好的做法,但 W3C 的 XML 中的命名空间 建议,以使命名空间处理尽可能简单.我熟悉的大多数用于公共使用的 XML 词汇表都在它们的名称空间 URI 处提供了文档,尽管并非全部都提供.因此,您可以通过查找由负责实体发布的文档来找出属于名称空间的内容.如果他们在命名空间 URI 中提供它,那很容易;如果没有,那就更难了;在某些情况下,这个问题在实践中可能无法回答.生活有时很艰难.

Using URIs as namespace names also has the nice property that the definer of the namespace can put human- and machine-readable documentation of the namespace at the namespace URI. Some authorities recommend this as good practice, but it is not required by the W3C's Namespaces in XML recommendation, in order to keep namespace processing as simple as possible. Most of the XML vocabularies intended for public use that I'm familiar with do provide documentation at their namespace URIs, though not all do. So you find out what belongs to a namespace by finding documentation for it, issued by the responsible entities. If they provide it at the namespace URI, it's easy; if not, it's harder; in some cases the question may not be answerable in practice. Life is hard sometimes.

这篇关于在 DTD 中,为什么将命名空间作为 URL 给出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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