xmlxml-serializationxmlschemaset

Repeating elements with different labels


I have an xml repeating element that looks like this

<property label="V" name="volume" units="cm3" sourcetype="reported">...                                                        
</property>
<property label="P" name="pressure" units="atm" sourcetype="reported">...        
</property>
<property label="tau" name="residence time" units="ms" 
sourcetype="reported">...</property>

I want to build an xml schema for it so as to have the different labels names and units under the same tag name "property". Here is my attempt that shows errors

<xs:complexType>
<xs:sequence>
<xs:element label="V" name="volume" units="cm3" sourcetype="reported" />
<xs:element label="P" name="pressure" units="atm" sourcetype="reported" />

Thank you a lot


Solution

  • You have a sequence of elements property with attributes label, name, and so on.

    Therefore, the schema may look like this

    <xs:complexType>
      <xs:sequence>        
        <xs:element maxOccurs="unbounded" name="property">
          <xs:complexType>
            <xs:simpleContent>
              <xs:extension base="xs:string">
                <xs:attribute name="label" type="xs:string" use="required" />
                <xs:attribute name="name" type="xs:string" use="required" />
                <xs:attribute name="units" type="xs:string" use="required" />
                <xs:attribute name="sourcetype" type="xs:string" use="required" />
              </xs:extension>
            </xs:simpleContent>
          </xs:complexType>
        </xs:element>        
      </xs:sequence>
    </xs:complexType>