Reputation: 21
I am using the following XSD:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xs:element name="root">
<xs:complexType mixed="true">
<xs:sequence>
<xs:element name="value" minOccurs="1" maxOccurs="5" type="new_type"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="new_type" mixed="true">
<xs:choice>
<xs:element name="function"/>
<xs:element name="something_else"/>
</xs:choice>
</xs:complexType>
</xs:schema>
The following XML file fails on line: abc
<?xml version="1.0" encoding="UTF-8"?>
<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="test.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<value><function/></value>
<value><function/></value>
<value>abc</value>
abc
</root>
Despite mixed="true" for complexType new_type on line 11 of XML, the validation of this XML file fails since it expects an element specified within xs:choice.
I need to be able to specify just a value in addition to element .
How should I change my XSD file?
Thanks,
Boris
Upvotes: 2
Views: 1169
Reputation: 151441
If you add minOccurs="0"
to your <xsd:choice>
, it will validate:
<xs:complexType name="new_type" mixed="true">
<xs:choice minOccurs="0">
<xs:element name="function"/>
<xs:element name="something_else"/>
</xs:choice>
</xs:complexType>
Otherwise, you need to have one element in addition to any character data you may have in it.
Upvotes: 2