xmlxsdxmlschema

XSD - List with all fixed values


What would be the correct XML Schema declaration for:

...<answersList>
    <question quest="Name?" cod="n_name">Variable Content</question>
    <question quest="Weight?" cod="n_weight">Variable Content</question>
</answersList>...

Every value for both attributes should be in the XSD enumeration.

So far I tried: (It doesen't work)

        <xs:element name="question">
            <xs:complexType>
              <xs:attribute name="quest">
                <xs:restriction base="xs:string">
                    <xs:enumeration value="Name?"/>
                    <xs:enumeration value="Weight?"/>
                </xs:restriction>
            </xs:attribute>
            <xs:attribute name="cod">
                <xs:restriction base="xs:string">
                    <xs:enumeration value="n_name"/>
                    <xs:enumeration value="n_weight"/>
                </xs:restriction>
            </xs:attribute>
          </xs:complexType>
        </xs:element>

Using this web to test: https://www.freeformatter.com/xml-validator-xsd.html


Solution

  • In XML Schema, the name of a tag identifies its type and the type describes the allowed content. When a tag repeats, each occurrence has the same type.

    So you cannot apply one set of rules to the attributes in //answersList/question[1] and a different set of rules to the attributes in //answersList/question[2].