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
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]
.
It seems to me that what you are actually looking for is cross-node constraints: "if X is A then Y must be B". That can be achieved using assertions in XSD 1.1; it can't be achieved in XSD 1.0.
You can constrain each of the attributes to a fixed set of values using an enumeration type (a simple type defined by restricting xs:string
with an enumeration facet), and you can define cross-attribute constraints using assertions, provided that you use an XSD 1.1 processor.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.