To determine how often an element can occur, DTDs use symbols (e.g., *, +, ?) and XML Schemas use attributes (e.g., minOccurs, maxOccurs). Relax NG is more, well, straightforward.
In Relax NG, to state that a tag may be used zero or more times, place a wrapper tag around it called <zeroOrMore>:
<zeroOrMore>
<element name="mytag">
<text/>
</element>
</zeroOrMore>
Similarly, for one or more occurrence, use the <oneOrMore> wrapper around the target element:
<oneOrMore>
<element name="mytag">
<text/>
</element>
</oneOrMore>
And then for optional elements, you use the <optional> wrapper:
<optional>
<element name="mytag">
<text/>
</element>
</optional>
Note that if there isn't an occurrence indicator on an element that it is required and can only occur once.
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.