当且仅当 DTD 中的元素不存在子元素时才需要定义属性

发布于 2024-09-30 00:37:13 字数 244 浏览 0 评论 0原文

考虑 DTD 中的以下定义:

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

我的问题是,当且仅当不存在 calculator 元素时,我希望定义 uri 属性。

有没有办法要求这个?

Consider the following definition from a DTD:

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

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

∞梦里开花 2024-10-07 00:37:13

@亚历杭德罗是对的。这对于 DTD 是不可能的,对于 XML Schema 也是不可能的。您可以使用具有RelaxNG架构的共现约束来做到这一点,或者您可以将 Schematron 与任何这些架构语言结合使用。

我之前已经通过使用带有模式的嵌入式 schematron 规则解决了类似的问题(在 XFront< 上与 XSD 对此进行了很好的讨论) /a> 以及 XML.com 上的 RelaxNG) 。我最近在纯 RelaxNG 中做了类似的事情,但是你有一个只能以一种形式表达的模式。

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文