XML : XSD: multiple groups with the same elements

I am attempting to validate XML that can only be read, not changed. I know what is possible in the XML and its structure, but not what will be received. Some of these have elements with the same name as others, either being exactly the same, or having different types, etc.

Is there a way to remove the groups from the scope of each other, or will I have to separate the XML, validate the chunks separately, and so on? I have provided an example of one of my attempts below for clarification of what I am attempting.

  <?xml version="1.0" encoding="UTF-8"?>  <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">    <xs:element name="root">      <xs:complexType>        <xs:sequence>          <xs:element maxOccurs="8" minOccurs="8" name="request">            <xs:complexType>              <xs:choice maxOccurs="unbounded" minOccurs="1">                <xs:group ref="group1"/>                <xs:group ref="group2"/>                <xs:group ref="group3"/>              </xs:choice>            </xs:complexType>          </xs:element>        </xs:sequence>      </xs:complexType>    </xs:element>    <xs:group name="group1">      <xs:sequence>        <xs:element name="hello" minOccurs="0" type="xs:string"/>      </xs:sequence>    </xs:group>    <xs:group name="group2">      <xs:sequence>        <xs:element name="hello" minOccurs="0" type="xs:string"/>        <xs:element name="world" minOccurs="0" type="xs:string"/>      </xs:sequence>    </xs:group>    <xs:group name="group3">      <xs:sequence>        <xs:element name="hello" minOccurs="0" type="xs:integer"/>        <xs:element name="world" minOccurs="0" type="xs:boolean"/>      </xs:sequence>    </xs:group>  </xs:schema>    

No comments:

Post a Comment