DTD 实体与 XML 模式元素 [英] DTD Entities vs XML-Schema Elements

查看:15
本文介绍了DTD 实体与 XML 模式元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用文档 DTD 我执行了以下操作:

Using an Document DTD I did the following:

文件.xsl:

<!DOCTYPE xsl:stylesheet[
  <!ENTITY red "rgb(255,0,0)">
]>

<xsl:stylesheet>
   [...]
   <xsl:attribute name="color">&red;</xsl:attribute>
   [...]
</xsl:stylesheet>

我想将所有内容都更改为 XML-Schema.所以我尝试了:

I wanted to change everything to XML-Schema. So I tried:

文件.xsd:

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <xsd:element name="red" type="xs:token" fixed="rgb(255,0,0)" />
</xsd:schema>

文件.xsl:

<xsl:stylesheet
    xmlns:defs="http://www.w3.org/2001/XMLSchema-instance"
    defs:noNamespaceSchemaLocation="file.xsd">

    [...]
    <xsl:attribute name="color"><defs:red/></xsl:attribute>
    [...]
</xsl:stylesheet>

现在通过 Xalan red 解析文件不像 DTD 版本那样被翻译.我的错误在哪里?解析过程中是否没有读取Schema文件?

Now parsing the file via Xalan red is not translated like in the DTD version. Where is my error? Are Schema files not read during the parsing process?

推荐答案

元素定义中的 fixed 属性不会告诉解析器进行文本替换.它只是意味着元素的值必须始终相同.

The fixed attribute in an element definition does not tell a parser to do a text substitution. It simply means that the value of the element must always be the same.

事实上,我相信您的 XSLT 生成的 XML 不会针对您的架构进行验证,因为 <defs:red> 元素的值不是 "rgb(255,0,0)".即使您使用 default 而不是 fixed,这也不是文本替换.这只是意味着,如果没有指定值,当在 DOM 实例中查询该值时,您会发现该值设置为rgb(255,0,0)".

In fact, I believe your XSLT is producing XML that will not validate against your schema, since the value of the <defs:red> element is not "rgb(255,0,0)". Even if you used default instead of fixed, this is not a text substitution. It just means that, if no value is specified, when the value is queried in a DOM instance, you'll find the value set to "rgb(255,0,0)".

这篇关于DTD 实体与 XML 模式元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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