Search code examples
xmlxsdxsd-validationxml-validationxsd-1.1

Set multiple values for an element in XML


I am new to schema design.

I am trying to set multiple values to a element in XML like shown below:

<EVENT>SYS_EVENT, TEMP_EVENT </EVENT>

I tried various schema designs for element EVENT using lists, enumeration etc.

But quite unfortunately it doesn't seem to work for me. I tried white spaces instead of comma, still it sets single value.

I would really appreciate any help.

I am using Altova XMLSpy for schema design.

<xs:element name="EVENT">
    <xs:simpleType>
        <xs:list>
            <xs:simpleType>
                <xs:restriction base="xs:string">
                    <xs:enumeration value="SYS_EVT"/>
                    <xs:enumeration value="CON_MGT_EVT"/>
                    <xs:enumeration value="PWR_MGT_EVT"/>
                    <xs:enumeration value="TEMP_EVT"/>
                    <xs:enumeration value="APP_MGT_EVT"/>
                    <xs:enumeration value="CFG_MGT_EVT"/>
                </xs:restriction>
            </xs:simpleType>
         </xs:list>
    </xs:simpleType>
</xs:element>

Solution

  • You are very close -- just two simple changes to make:

    1. Use spaces, not commas, between list members.
    2. Be careful to match spelling exactly: SYS_EVENT vs SYS_EVT, etc.

    So, if you leave your XSD as is and change your XML,

    <EVENT>SYS_EVT TEMP_EVT</EVENT>
    

    then the XML will validate successfully against your XSD.