I would like my XML instance documents to consist of one or more <a/>
elements followed by an equal number of <b/>
elements. Here are some valid instances:
<a/><b/>, <a/><a/><b/><b/>, <a/><a/><a/><b/><b/><b/>
I want to use XML Schema 1.0 to implement it.
I tried this approach:
<xs:group name="context-free-language">
<xs:sequence>
<xs:element name="a" fixed="a" />
<xs:group ref="context-free-language" minOccurs="0" />
<xs:element name="b" fixed="b" />
</xs:sequence>
</xs:group>
Unfortunately, circular group references are not allowed.
Any suggestions on how to implement this?
XML Schema 1.0 provides only partial support for context-free grammars. Regrettably, it does not support grammars that require an equal number of a's and b's. On the other hand, it does support some context-free grammars. I wrote an article which explains this: http://www.xfront.com/XML-Schema-1-0-and-Relax-NG-Partially-Support-Context-Free-Grammars.pdf