Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XML Schema: how to have multiple identical elements?

Tags:

xml

schema

xsd

I'm having quite a hard time on constructing my 1st XML Schema. I need it to verify the correctness of an XML document that forms a questionnaire.
So here's the section in don't get:

I changed the source. The 1st answer refers to this code:

<root>
    <values>
        <value>Lorem</value>
        <value>ipsum</value>
        <value>dolor</value>
    </values>
</root>

Now my actual goal is this:

<requires>
    <require requires-id="2" type="included">
        <values>  
            <value isRequired="true">Lorem</value>
            <value isRequired="false">Lorem</value>
            <value isRequired="false">Lorem</value>
        </values>
    </require>
    <require requires-id="5" type="excluded">
        <values>  
            <value isRequired="true">Lorem</value>
            <value isRequired="false">Lorem</value>
        </values>
    </require>
</requires>

Can anyone please help to make a proper Schema? I'm using Sun Multi-Schema XML Validator (MSV) to validate the document against the Schema.

Thanks in advance,
Steff

like image 258
stfn Avatar asked Feb 27 '23 04:02

stfn


1 Answers

This should do it for the 1st xml:

<xs:complexType name="Values">
    <xs:sequence>
        <xs:element name="value" minOccurs="0" maxOccurs="200">
            <xs:complexType>
                <xs:simpleContent>
                    <xs:extension base="xs:string">
                        <xs:attribute name="isOnlyOption" type="xs:boolean"/>
                    </xs:extension>
                </xs:simpleContent>
            </xs:complexType>
        </xs:element>
    </xs:sequence>
</xs:complexType>
<xs:element name="values" type="Values" minOccurs="0"/>

The 2nd one looks like this:

<xs:element name="requires" minOccurs="0">
    <xs:complexType>
        <xs:sequence>
            <xs:element name="require" minOccurs="1" maxOccurs="200">
                <xs:complexType>
                    <xs:attribute name="requires-id" type="xs:IDREF"/>
                    <xs:attribute name="type" type="RequiresType"/>
                    <xs:all>
                        <xs:element name="values" type="Values" minOccurs="0" maxOccurs="1"/>
                    </xs:all>
                </xs:complexType>
            </xs:element>
        </xs:sequence>
    </xs:complexType>
</xs:element>

Note the reference to the custom data type 'Values' from the 1st snippet.

Thanks,
Steff

like image 112
stfn Avatar answered Mar 08 '23 00:03

stfn