在DTD中,为什么将名称空间指定为URL? [英] In DTDs, why are namespaces given as a URL?

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

问题描述

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

Apparently, the namespace URL that follows xmlns in HMTL 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'.

现在,只要满足第三个条件,您就可以将设计用来处理的词汇中的污点"与其他任何污点"区分开来(只需看一下它们的扩展名!).

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作为最成功的注册中心之一的piggy带方式:一种将域名系统维护在Internet核心的方法.只要名称空间名称的发明者遵循仅在他们拥有或控制的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中的命名空间

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天全站免登陆