开发者

Order of sequence of elements with different cardinalities in a doctype

开发者 https://www.devze.com 2023-02-03 22:01 出处:网络
I\'m creating a doctype for XML files I\'m working with to simplify their validation. However, I\'d like to express something and I don\'t know how.

I'm creating a doctype for XML files I'm working with to simplify their validation. However, I'd like to express something and I don't know how.

I have <test> elements. These elements can have up to one <description> tag, but must have 1+ <node> child, and any number of <argument> tags. However, I'd like it to be possible to specify them in no particular order. For instance, this snippet:

<test>
    <node>foo</node>
    <argument>baz</argument>
    <description>bar</description>
</test>

should be a valid <test> representation.

The first obvious answer that came to my mind was this:

<!ELEMENT test (description?, node+, argument*)>

but it's my understanding that the comma operator will require the elements to be present in the precise order they're specified.

How can I make a doctype that will not h开发者_运维百科ave this requirement?


This is why DTD was abandoned in favour of XML Schema - DTD isn't expressive enough, even for simple cases like this.

I stronly suggest you forget DTD, and use a Schema.


Use RELAX NG instead of DTDs.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号