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)