没有严格的元素顺序如何定义DTD?
作为一名 XML“菜鸟”,我发现在创建针对 DTD 进行验证的 XML 流/文件时元素顺序的重要性。是否可以定义一个不依赖于元素顺序的 DTD?如果,那么请提供语法示例。
As an XML "noob" I have discovered the importance of element order when creating an XML stream/file that is validated against a DTD. Is it possible to define a DTD that is not order dependent on elements ? If, so please provide syntactic example.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您使用或(垂直管道)和重复(星号:)
这意味着
eltype1
可以包含任意数量的eltype2重复
或eltype3
。You use or (a vertical pipe) and repeat (an asterisk:)
This means
eltype1
can contain any number of repetitions ofeltype2
oreltype3
.当前接受的答案的唯一问题是它不会以任何顺序仅强制每个元素之一。例如,您可以有 2 个
eltype2
元素,但没有eltype3
元素。如果您需要确保两个元素都存在并且每个元素仅出现一次,则这是更精确的元素声明:
内部子集中的示例:
The only issue with the currently accepted answer is that it doesn't force only one of each element in any order. For example, you could have 2
eltype2
elements and noeltype3
elements.If you need to be sure that both elements are present and that each occurs only one time, this is a more precise element declaration:
Example in an internal subset: