0

My xsd looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">

    <xs:element name="modal">

        <xs:complexType>

            <xs:sequence>

                <xs:element name="inputs" minOccurs="0">
                    <xs:complexType>
                        <xs:choice maxOccurs="unbounded">
                            <xs:element ref="string-option"></xs:element>
                        </xs:choice>
                    </xs:complexType>
                </xs:element>

            </xs:sequence>

        </xs:complexType>

    </xs:element>

    <xs:element name="string-option">
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="option" minOccurs="0" maxOccurs="unbounded"></xs:element>
                <xs:group ref="base-option-group"></xs:group>
                <xs:element ref="option" minOccurs="0" maxOccurs="unbounded"></xs:element>
            </xs:sequence>
        </xs:complexType>
    </xs:element>

    <xs:element name="option" type="base-option-type"></xs:element>

    <xs:simpleType name="base-option-type">
        <xs:restriction base="xs:string">
            <xs:pattern value="[^,]+"></xs:pattern>
        </xs:restriction>
    </xs:simpleType>

    <xs:group name="base-option-group">
        <xs:choice>
            <xs:element ref="option"></xs:element>
            <xs:element ref="option-selected"></xs:element>
        </xs:choice>
    </xs:group>

    <xs:element name="option-selected" type="base-option-type"></xs:element>

</xs:schema>

What I would expect is, that <string-option> must at least contain one element <option> or <option-selected> (any order) and cannot contain more than one <option-selected>.

Strangely, the following xml

<?xml version="1.0" encoding="UTF-8"?>
<modal xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../src/customElements/modal.xsd">
    <inputs>
        <string-option>
            <option>Option A</option>
            <option>Option B</option>
        </string-option>
    </inputs>
</modal>

yields the error Child elements are missing from element 'string-option'.

x xx xxx xxxx xxxxx Added full xml/xsd xxxx xxx xx x

Full Error message in VS Code is

Child elements are missing from element 'string-option'.

The following elements are expected:
 - option
 - option
 - option-selected

Error indicated by:
 {the schema}
with code:xml(cvc-complex-type.2.4.b)
DonFuchs
  • 371
  • 2
  • 14
  • Which parser did you use? Doesn't it indicate what is missing? – Martin Honnen Oct 24 '22 at 13:51
  • Also is that XSD 1.0 or 1.1? For 1.0 I see an error with the schema and Xerces saying 'option and option (or elements from their substitution group) violate "Unique Particle Attribution". During validation against this schema, ambiguity would be created for those two particles' about the complex type in `string-option`. – Martin Honnen Oct 24 '22 at 13:56
  • Saxon EE also tells me "Ambiguous content model: element particle ` – Martin Honnen Oct 24 '22 at 13:58
  • I added some more information... – DonFuchs Oct 24 '22 at 14:50
  • That is odd, in my understanding and with two processors (Xerces and Saxon) checked, your schema is not valid, so I am not sure why VS code tries to give a validation message about any XML instance document, it should say the schema is not valid. But I don't know which processor VS code uses, let's wait what others with more insight have to say. – Martin Honnen Oct 25 '22 at 12:58
  • Possibly duplicate of https://stackoverflow.com/questions/74184849/ambiguous-content-model-allowing-individual-elements-or-specific-combinations – Dijkgraaf Oct 25 '22 at 22:13
  • @Dijkgraaf Well not really... – DonFuchs Oct 26 '22 at 13:38
  • Very similar though. I don't think you can achieve it in XSD 1.0. Possibly only with XSD 1.1. Your schema does come up with an errors as being Ambiguous in Visual Studio as well. – Dijkgraaf Oct 26 '22 at 19:42

0 Answers0