仅当DTD中的元素不存在子元素时,才需要定义属性 [英] Requiring an attribute be defined if and only if a child element is not present for an element in a DTD

查看:84
本文介绍了仅当DTD中的元素不存在子元素时,才需要定义属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑DTD中的以下定义:

Consider the following definition from a DTD:

<!ELEMENT application (calculator)?>
<!ATTLIST application
        uri CDATA #REQUIRED
>

我的问题是我想要 uri 仅当没有 calculator 元素时才定义属性。

My problem is that I want the uri attribute to be defined if and only if there is not a calculator element.

是否有一种方法可以要求此属性?

Is there a way to require this?

推荐答案

@Alejandro是正确的。 DTD无法实现, XML模式也无法实现。您可以使用带有 RelaxNG 架构的共现约束来执行此操作,也可以将 Schematron 与任何这些模式语言结合使用。

@Alejandro is right. That's not possible with a DTD nor is it possible with XML Schema. You can do this using a co-occurrence constraint with a RelaxNG schema or you could use Schematron in conjunction with any of those schema languages.

我以前通过使用带有模式的嵌入式schematron规则解决了此类问题(在 XFront ,并在 XML.com )。我最近在纯RelaxNG中做过类似的事情,但是您有一个只能以这种形式表示的模式。

I've resolved issues like this before by using embedded schematron rules with schemas (good discussion of this with XSD on XFront and with RelaxNG on XML.com). I've recently been doing something similar in pure RelaxNG but then you have a schema that can only be expressed in that one form.

这篇关于仅当DTD中的元素不存在子元素时,才需要定义属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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