Xsd select multiple values ​​from enumeration or equivalent type

I have the following XSD sample

<xs:element name="days" minOccurs="0">
    <xs:simpleType>
        <xs:restriction base="xs:string">
            <xs:enumeration value="Monday"/>
            <xs:enumeration value="Tuesday"/>
            <xs:enumeration value="Wednesday"/>
            <xs:enumeration value="Thursday"/>
            <xs:enumeration value="Friday"/>
            <xs:enumeration value="Saturday"/>
            <xs:enumeration value="Sunday"/>
        </xs:restriction>
    </xs:simpleType>
</xs:element>

The xml instance should contain several values ​​from the list, but limit what they enter into the enumeration above, for example, <days> Saturday, Wednesday </days>. Is it possible?

+2
source share
3 answers

If you can lose a comma (not supported as a separator in XSD) and be happy with spaces, then this is your solution:

<?xml version="1.0" encoding="utf-8" ?>
<!-- XML Schema generated by QTAssistant/XSD Module (http://www.paschidev.com) -->
<xsd:schema elementFormDefault="qualified" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <xsd:element name="days">
        <xsd:simpleType>
            <xsd:list>
                <xsd:simpleType>
                    <xsd:restriction base="xsd:string">
                        <xsd:enumeration value="Monday"/>
                        <xsd:enumeration value="Tuesday"/>
                        <xsd:enumeration value="Wednesday"/>
                        <xsd:enumeration value="Thursday"/>
                        <xsd:enumeration value="Friday"/>
                        <xsd:enumeration value="Saturday"/>
                        <xsd:enumeration value="Sunday"/>
                    </xsd:restriction>                  
                </xsd:simpleType>               
            </xsd:list>
        </xsd:simpleType>
    </xsd:element>
</xsd:schema>

You mainly use a list, so something like this would be perfectly fair:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<!-- Sample XML generated by QTAssistant (http://www.paschidev.com) -->
<days xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">Monday Tuesday Wednesday </days>

To be active here ... if, for example, one could guarantee the uniqueness of values, then this cannot be applied in XSD.

+4
source

, , :

.*day(,.*day)*

*.day (Monday|Tuesday|...).

+1

, :

<xs:simpleType name="DayOfWeek">
  <xs:restriction base="xs:string">
    <xs:pattern value="(Mon|Tues|Wed)(,(Mon|Tues|Wed))*"/>
  </xs:restriction>
</xs:simpleType>

, , "Mon, Mon, Mon, , Mon", , . , : Mon, Mon, Mon .

0

Source: https://habr.com/ru/post/1584424/


All Articles