XML文档可以同时遵循DTD和XML Schema吗? [英] Can an XML document follow both a DTD and an XML Schema?

查看:112
本文介绍了XML文档可以同时遵循DTD和XML Schema吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

指定XML文档同时遵循DTD 模式是否合法?
两者不会互相冲突吗?

Is it legal for an XML document to specify that it follows both a DTD and a Schema? Won't the two conflict with one another?

推荐答案

从技术上讲,我认为您在DTD上会遇到问题而不是识别用于引用架构的属性(名称空间声明和架构位置)。

Technically I think you would have problems with the DTD not recognizing the attributes for referencing the schema (the namespace declaration and the schema location).

但是,我认为这取决于您如何验证XML以及是否可以忽略DTD进行验证(如果指定了模式)。

However I think it depends on how you're validating your XML and whether or not you can ignore the DTD for validation if a schema is specified.

此外,对于您的分配,您确定必须同时引用相同的XML实例吗?也许您可以有2个版本的XML。

Also, for your assignment are you sure you have to reference both from the same XML instance? Maybe you could have 2 versions of the XML; one that references the DTD and one that references the schema?

这里还有另外两个可能的选择...

Here's two other possible options...

声明架构属性:

<!DOCTYPE doc [
<!ELEMENT doc (test)>
<!ATTLIST doc
          xmlns:xsi CDATA #IMPLIED
          xsi:noNamespaceSchemaLocation CDATA #IMPLIED>
<!ELEMENT test (#PCDATA)>
]>
<doc xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:noNamespaceSchemaLocation="test.xsd">
    <test>Test Doc</test>
</doc>

使用处理指令来引用架构:

<!DOCTYPE doc [
<!ELEMENT doc (test)>
<!ELEMENT test (#PCDATA)>
]>
<?xml-model href="test.xsl"?>
<doc>
    <test>Test Doc</test>
</doc>

这篇关于XML文档可以同时遵循DTD和XML Schema吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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