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

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

问题描述

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

Using an Document DTD I did the following:

file.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:

file.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>

file.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版本不同。我的错误在哪里?在解析过程中是否不读取模式文件?

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?

推荐答案

已修复 元素定义中的属性不会告诉解析器进行文本替换。它仅表示元素的值必须始终相同。

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.

实际上,由于< defs:red>的值,我相信您的XSLT正在生成无法针对您的模式进行验证的XML。 元素不是 rgb(255,0,0)。即使您使用默认值而不是固定的,这也不是文本替换。这只是意味着,如果未指定任何值,则在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-Schema元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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