Order of sequence of elements with different cardinalities in a doctype
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.
精彩评论