热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

DTD与XSD定义的XML语言的范围-ScopeofXMLlanguagesdefinedbyDTDvsXSD

Doesthefollowingpropositionshold:ForeveryDTDthereisanXSDthatdefinesexactlythesamela

Does the following propositions hold: For every DTD there is an XSD that defines exactly the same language, and for every XSD there is a DTD that defines exactly the same language. Or put another way: The collection of languages defined by any DTD is exactly the the collection of languages defined by any XSD?

以下命题是否成立:对于每个DTD,都有一个定义完全相同语言的XSD,并且对于每个XSD,都有一个定义完全相同语言的DTD。或换句话说:任何DTD定义的语言集合都是任何XSD定义的语言集合?

Expanding on the question a little: An XML document is basically a large string. A language is a collection of strings. For example, the (infinite) set of all MathML documents is a language, and so is the set of all RSS documents and so on. MathML (RSS, ...) is also a proper subset of the (infinite) set of all XML documents. You can use DTD or XSD to define such a subset of XML.

稍微扩展一下这个问题:XML文档基本上是一个大字符串。语言是字符串的集合。例如,所有MathML文档的(无限)集合都是一种语言,所有RSS文档的集合也是如此。 MathML(RSS,...)也是所有XML文档(无限)集的适当子集。您可以使用DTD或XSD来定义这样的XML子集。

Now, every DTD defines exactly one language. But if you think of all possible DTDs, you get a set of languages. My question is, is this set exactly the same as the one you get from all possible XSDs? If so, then DTD and XSD are equivalent in the sense that the scope of XML languages defined by either is equal.

现在,每个DTD都只定义一种语言。但是如果你想到所有可能的DTD,你会得到一套语言。我的问题是,这个设置与你从所有可能的XSD获得的设置完全相同吗?如果是这样,那么DTD和XSD在两者所定义的XML语言范围相等的意义上是等价的。

Why is this question important? If both DTD and XSD are equivalent then it is possible to write a program that takes a DTD as input and gives you an equivalent XSD, and another program that does the opposite. I know there are quite a few programs out there that claim to do exactly this, but I'm in doubt whether or not that's actually possible.

为什么这个问题很重要?如果DTD和XSD都是等效的,则可以编写一个程序,该程序将DTD作为输入并为您提供等效的XSD,另一个程序则执行相反的操作。我知道有很多程序声称要做到这一点,但我怀疑这是否真的有可能。

2 个解决方案

#1


5  

An interesting question; well asked!

一个有趣的问题;好问!

The answer is "no", in both directions.

两个方向的答案都是“不”。

Here is a DTD which has no equivalent in XSD:

这是一个在XSD中没有等效的DTD:



The set of character sequences accepted by this DTD includes both and &egbdf;, but not &beadgcf;.

该DTD接受的字符序列集包括 &egbdf; ,但不包括 &beadgcf; 。

Since XSD validation operates on an information set in which entities have all already been expanded, no XSD schema can distinguish the third case from the second.

由于XSD验证在一个实体已经扩展的信息集上运行,因此没有XSD架构可以区分第三种情况和第二种情况。

A second area where DTDs can express constraints not expressible in XSD involves NOTATION types. I won't give an example; the details are too complicated for me to remember them correctly without looking them up, and not interesting enough to make me want to do so.

DTD可以表达在XSD中不可表达的约束的第二个区域涉及NOTATION类型。我不会举一个例子;细节太复杂了,我不能正确地记住它们,而且没有足够的兴趣让我想要这么做。

A third area: DTDs treat namespace attributes (aka namespace declarations) and general attributes in the same way; a DTD can therefore constrain the appearance of namespace declarations in documents. An XSD schema cannot. The same applies to attributes in the xsi namespace.

第三个方面:DTD以相同的方式处理命名空间属性(也称为命名空间声明)和一般属性;因此,DTD可以约束文档中名称空间声明的外观。 XSD架构不能。这同样适用于xsi名称空间中的属性。

If we ignore all of those issues, and formulate the question with respect only to character sequences containing no references to named entities other than the pre-defined entities lt, gt, etc., then the answer changes: for every DTD not involving NOTATION declarations, there is an XSD schema that accepts precisely the same set of documents after entity expansion and with 'same' defined in a way that ignores namespace attributes and attributes in the xsi namespace.

如果我们忽略所有这些问题,并且只针对不包含对预定义实体lt,gt等以外的命名实体的引用的字符序列来表达问题,则答案会发生变化:对于每个不涉及NOTATION声明的DTD ,有一个XSD架构在实体扩展后接受完全相同的文档集,并且以忽略xsi命名空间中的命名空间属性和属性的方式定义“相同”。

In the other direction, the areas of difference include these:

在另一个方向,差异的领域包括:

  • XSD is namespace aware: the following XSD schema accepts any instance of element e in the specified target namespace, regardless of what prefix is bound to that namespace in the document instance.

    XSD是名称空间感知:以下XSD架构接受指定目标名称空间中元素e的任何实例,而不管文档实例中哪个前缀绑定到该名称空间。

    
      
    
    

    No DTD can successfully accept all and only the e elements in the given namespace.

    没有DTD可以成功接受给定命名空间中的所有和仅e元素。

  • XSD has a richer set of datatypes and can use datatypes to constrain elements as well as attributes. The following XSD schema has no equivalent DTD:

    XSD具有更丰富的数据类型集,可以使用数据类型来约束元素和属性。以下XSD架构没有等效的DTD:

    
      
    
    

    This schema accepts the document 42 but not the document 42d Street. No DTD can make that distinction, because DTDs have no mechanism for constraining #PCDATA content. The closest DTD would be , which accepts both sample documents.

    此架构接受文档 42 ,但不接受文档 42d Street 。没有DTD可以做出这种区分,因为DTD没有约束#PCDATA内容的机制。最接近的DTD是 ,它接受两个样本文件。

  • XSD's xsi:type attribute allows in-document modifications of content models. The XSD schema described by the following schema document has no equivalent DTD:

    XSD的xsi:type属性允许对内容模型进行文档内修改。以下架构文档描述的XSD架构没有等效的DTD:

    
      
        
          
        
      
      
        
          
        
      
    
      
    
    

    This schema accepts the document and rejects the document . DTDs have no mechanism for making content models depend on an attribute value given in the document instance.

    此架构接受文档 并拒绝文档 。 DTD没有使内容模型依赖于文档实例中给出的属性值的机制。

  • XSD wildcards allow the inclusion of arbitrary well-formed XML among the children of specified elements; the closest one can come to that with a DTD is to use an element declaration of the form , which is not the same because it requires declarations for all the elements which in fact appear.

    XSD通配符允许在指定元素的子元素中包含任意格式良好的XML;使用DTD最接近的是使用 形式的元素声明,这是不一样的,因为它需要声明实际出现的所有元素。

  • XSD 1.1 provides assertions and conditional type assignment, which have no analogues in DTDs.

    XSD 1.1提供断言和条件类型赋值,它们在DTD中没有类似物。

There are probably other ways in which the expressive power of XSD exceeds that of DTDs, but I think the point has been illustrated adequately.

XSD的表现力可能超过DTD的其他方式,但我认为这一点已得到充分说明。

I think a fair summary would be: XSD can express everything DTDs can express, with the exception of entity declarations and special cases like namespace declarations and xsi:* attributes, because XSD was designed to be able to do so. So the loss of information when translating a DTD to an XSD schema document is relatively modest, well understood, and mostly involves things most vocabulary designers regard as DTD artefacts not of substantive interest.

我认为一个公平的总结是:XSD可以表达DTD可以表达的所有内容,但实体声明和名称空间声明和xsi:*属性等特殊情况除外,因为XSD旨在能够这样做。因此,在将DTD翻译成XSD模式文档时丢失信息是相对适度的,易于理解的,并且主要涉及大多数词汇设计者认为不具有实质意义的DTD文物的事物。

XSD can express more than DTDs can, again because XSD was designed to do so. In the general case, translation from XSD to DTD necessarily involves loss of information (the set of documents accepted may need to be larger, or smaller, or to be an overlapping set). Different choices can be made about how to manage the loss of information, which gives the question "How does one best translate an XSD into DTD form?" a certain theoretical interest. (Very few people, however, seem to find it an interesting question in practice.)

XSD可以表达超过DTD的能力,因为XSD的设计也是如此。在一般情况下,从XSD到DTD的转换必然涉及信息丢失(接受的文档集可能需要更大或更小,或者是重叠集)。可以对如何管理信息丢失做出不同的选择,这就提出了“如何最好地将XSD转换为DTD形式?”的问题。一定的理论兴趣。 (然而,很少有人在实践中发现这是一个有趣的问题。)

All of this focuses, as did your question, on documents as character sequences, on languages as document sets, and on schema languages as generators of languages in that sense. Issues of maintainability and information present in the schema that does not turn into differences in the extension of document sets (e.g. the treatment of class hierarchies in the document model) is left out of account.

所有这一切都集中在您的问题上,作为字符序列的文档,作为文档集的语言,以及作为这种意义上的语言生成器的模式语言。在模式中存在的可维护性和信息的问题不会变成文档集的扩展中的差异(例如,文档模型中的类层次结构的处理)。

#2


1  

Without qualifiers, the answer is no.

没有限定词,答案是否定的。

You have to define what is it you call a "language". In my mind, these you refer to are languages meant to define document schemata. A schemata defines constraints on the document structure and content. The constraints expressible by XSD are far more powerful than DTD. So no, they wouldn't be the same.

你必须定义你称之为“语言”的东西。在我看来,你所指的是用于定义文档模式的语言。模式定义了对文档结构和内容的约束。 XSD可以表达的约束比DTD强大得多。所以不,他们不会是一样的。

A comparison of DTD vs. XSD might help you understand why not.

DTD与XSD的比较可能有助于您理解为什么不这样做。


推荐阅读
  • CF:3D City Model(小思维)问题解析和代码实现
    本文通过解析CF:3D City Model问题,介绍了问题的背景和要求,并给出了相应的代码实现。该问题涉及到在一个矩形的网格上建造城市的情景,每个网格单元可以作为建筑的基础,建筑由多个立方体叠加而成。文章详细讲解了问题的解决思路,并给出了相应的代码实现供读者参考。 ... [详细]
  • Python正则表达式学习记录及常用方法
    本文记录了学习Python正则表达式的过程,介绍了re模块的常用方法re.search,并解释了rawstring的作用。正则表达式是一种方便检查字符串匹配模式的工具,通过本文的学习可以掌握Python中使用正则表达式的基本方法。 ... [详细]
  • 本文介绍了一个题目的解法,通过二分答案来解决问题,但困难在于如何进行检查。文章提供了一种逃逸方式,通过移动最慢的宿管来锁门时跑到更居中的位置,从而使所有合格的寝室都居中。文章还提到可以分开判断两边的情况,并使用前缀和的方式来求出在任意时刻能够到达宿管即将锁门的寝室的人数。最后,文章提到可以改成O(n)的直接枚举来解决问题。 ... [详细]
  • VScode格式化文档换行或不换行的设置方法
    本文介绍了在VScode中设置格式化文档换行或不换行的方法,包括使用插件和修改settings.json文件的内容。详细步骤为:找到settings.json文件,将其中的代码替换为指定的代码。 ... [详细]
  • 本文讨论了使用差分约束系统求解House Man跳跃问题的思路与方法。给定一组不同高度,要求从最低点跳跃到最高点,每次跳跃的距离不超过D,并且不能改变给定的顺序。通过建立差分约束系统,将问题转化为图的建立和查询距离的问题。文章详细介绍了建立约束条件的方法,并使用SPFA算法判环并输出结果。同时还讨论了建边方向和跳跃顺序的关系。 ... [详细]
  • 本文介绍了如何在给定的有序字符序列中插入新字符,并保持序列的有序性。通过示例代码演示了插入过程,以及插入后的字符序列。 ... [详细]
  • 本文介绍了一种划分和计数油田地块的方法。根据给定的条件,通过遍历和DFS算法,将符合条件的地块标记为不符合条件的地块,并进行计数。同时,还介绍了如何判断点是否在给定范围内的方法。 ... [详细]
  • 本文介绍了解决二叉树层序创建问题的方法。通过使用队列结构体和二叉树结构体,实现了入队和出队操作,并提供了判断队列是否为空的函数。详细介绍了解决该问题的步骤和流程。 ... [详细]
  • 本文介绍了C函数ispunct()的用法及示例代码。ispunct()函数用于检查传递的字符是否是标点符号,如果是标点符号则返回非零值,否则返回零。示例代码演示了如何使用ispunct()函数来判断字符是否为标点符号。 ... [详细]
  • 本文介绍了UVALive6575题目Odd and Even Zeroes的解法,使用了数位dp和找规律的方法。阶乘的定义和性质被介绍,并给出了一些例子。其中,部分阶乘的尾零个数为奇数,部分为偶数。 ... [详细]
  • Linux环境变量函数getenv、putenv、setenv和unsetenv详解
    本文详细解释了Linux中的环境变量函数getenv、putenv、setenv和unsetenv的用法和功能。通过使用这些函数,可以获取、设置和删除环境变量的值。同时给出了相应的函数原型、参数说明和返回值。通过示例代码演示了如何使用getenv函数获取环境变量的值,并打印出来。 ... [详细]
  • [大整数乘法] java代码实现
    本文介绍了使用java代码实现大整数乘法的过程,同时也涉及到大整数加法和大整数减法的计算方法。通过分治算法来提高计算效率,并对算法的时间复杂度进行了研究。详细代码实现请参考文章链接。 ... [详细]
  • 本文介绍了南邮ctf-web的writeup,包括签到题和md5 collision。在CTF比赛和渗透测试中,可以通过查看源代码、代码注释、页面隐藏元素、超链接和HTTP响应头部来寻找flag或提示信息。利用PHP弱类型,可以发现md5('QNKCDZO')='0e830400451993494058024219903391'和md5('240610708')='0e462097431906509019562988736854'。 ... [详细]
  • 前景:当UI一个查询条件为多项选择,或录入多个条件的时候,比如查询所有名称里面包含以下动态条件,需要模糊查询里面每一项时比如是这样一个数组条件:newstring[]{兴业银行, ... [详细]
  • 3.223.28周学习总结中的贪心作业收获及困惑
    本文是对3.223.28周学习总结中的贪心作业进行总结,作者在解题过程中参考了他人的代码,但前提是要先理解题目并有解题思路。作者分享了自己在贪心作业中的收获,同时提到了一道让他困惑的题目,即input details部分引发的疑惑。 ... [详细]
author-avatar
手机用户2502906317
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有