Controlling what tags that can occur by using a control tag.

I need a way to validate that an element A's special elements follows when
someone enters 'A' as a name.
And likewize that the element B's special elements follows when someone enters
'B' as a name.

The below schema is my way of expression this, i wonder if this is valid?

Is this a good solution or is there a better way?

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="message">
    <xs:complexType>
      <xs:choice>
        <xs:sequence>
           <xs:element name="name">
             <xs:simpleType>
               <xs:restriction base="xs:string">
                 <xs:enumeration value="A"/>
               </xs:restriction>
             </xs:simpleType>
           </xs:element>
           <xs:element name="variables">
             <xs:complexType>
               <xs:sequence>
                 <xs:element name="a_variable"/>
               </xs:sequence>
             </xs:complexType>
           </xs:element>
        </xs:sequence>
        <xs:sequence>
           <xs:element name="name">
             <xs:simpleType>
               <xs:restriction base="xs:string">
                 <xs:enumeration value="B"/>
               </xs:restriction>
             </xs:simpleType>
           </xs:element>
           <xs:element name="variables">
             <xs:complexType>
               <xs:sequence>
                 <xs:element name="b_variable"/>
               </xs:sequence>
             </xs:complexType>
           </xs:element>
        </xs:sequence>
      </xs:choice>
    </xs:complexType>
  </xs:element>
</xs:schema>


<?xml version="1.0" encoding="UTF-8"?>
<message xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="E:\test.xsd">
  <name>A</name>
  <variables>
    <a_variable/>
  </variables>
  <name>B</name>
  <variables>
    <b_variable/>
  </variables>
</message>

Received on Wednesday, 27 March 2002 04:23:36 UTC