recursive definitions in XML Schema

Hi,

Does XML Schema supports recursive definitions? Where could I find some examples on this? I am trying to define a xsd for arithmetic expressions such as "(1+2)*6+3". The EBNF grammar is as below.

expr := term ("+" expr | "-" expr)*
term := unary ("*" term | "/" term)*
unary := "-" element | element
element := <NUMBER> | "(" expr ")"


The following is what I wrote for the above grammar in XML Schema. But it seems not working on validation checks for instant documents. Could anyone point out what was wrong with it. Thank you.

<xsd:element name="expression" type="exprType"/>
<xsd:complexType name="exprType">
 <xsd:sequence>
  <xsd:group ref="expr"/>
 </xsd:sequence>
</xsd:complexType>
<xsd:group name="expr">
 <xsd:sequence>
  <xsd:group ref="term"/>
  <xsd:group ref="expr2" minOccurs="0" maxOccurs="unbounded"/>
 </xsd:sequence>
</xsd:group>
<xsd:group name="expr2">
 <xsd:sequence>
  <xsd:element name="op1" type="operator1"/>
  <xsd:group ref="expr"/>
 </xsd:sequence>
</xsd:group>
<xsd:group name="term">
 <xsd:sequence>
  <xsd:group ref="unary"/>
  <xsd:group ref="term2" minOccurs="0" maxOccurs="unbounded"/>
 </xsd:sequence>
</xsd:group>
<xsd:group name="term2">
 <xsd:sequence>
  <xsd:element name="op2" type="operator2"/>
  <xsd:group ref="term"/>
 </xsd:sequence>
</xsd:group>
<xsd:group name="unary">
 <xsd:sequence>
  <xsd:element name="sign" type="xsd:string" fixed="-" minOccurs="0"/>
  <xsd:group ref="element"/>
 </xsd:sequence>
</xsd:group>
<xsd:group name="element">
 <xsd:sequence>
  <xsd:choice>
   <xsd:element name="number" type="xsd:integer"/>
   <xsd:group ref="bracket"/>
  </xsd:choice>
 </xsd:sequence>
</xsd:group>
<xsd:group name="bracket">
 <xsd:sequence>
  <xsd:element name="leftB" type="xsd:string" fixed="("/>
  <xsd:group ref="expr"/>
  <xsd:element name="rightB" type="xsd:string" fixed=")"/>
 </xsd:sequence>
</xsd:group>
<xsd:simpleType name="operator1">
 <xsd:restriction base="xsd:string">
  <xsd:enumeration value="+"/>
  <xsd:enumeration value="-"/>
 </xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="operator2">
 <xsd:restriction base="xsd:string">
  <xsd:enumeration value="*"/>
  <xsd:enumeration value="/"/>
 </xsd:restriction>
</xsd:simpleType>


Best regards.

Jim

Received on Wednesday, 20 June 2001 09:05:21 UTC