Xerces doesn't like choice of empty group

R

Ray Lischner

I have a schema that contains a choice of groups, and one of the groups
contains an empty sequence. I can validate an XML document and the
schema with some validators, but not Xerces. It says "Empty content not
valid for content model: '((one,two)|((a,b),c))', which indicates that
it is ignoring the "empty" group. I think Xerces is wrong, but I'm not
100% certain. What do you think?

The schema is:

<?xml version="1.0" ?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:group name="empty">
<xsd:sequence/>
</xsd:group>
<xsd:group name="numbers">
<xsd:sequence>
<xsd:element name="one" type="xsd:int"/>
<xsd:element name="two" type="xsd:int"/>
</xsd:sequence>
</xsd:group>
<xsd:group name="letters">
<xsd:sequence>
<xsd:element name="a" type="xsd:string"/>
<xsd:element name="b" type="xsd:string"/>
<xsd:element name="c" type="xsd:string"/>
</xsd:sequence>
</xsd:group>
<xsd:complexType name="list">
<xsd:sequence>
<xsd:element name="item" minOccurs="1" maxOccurs="3">
<xsd:complexType mixed="true">
<xsd:choice>
<xsd:group ref="empty"/>
<xsd:group ref="numbers"/>
<xsd:group ref="letters"/>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
<xsd:element name="root" type="list"/>
</xsd:schema>

Here's a sample XML document:

<?xml version="1.0" encoding="utf-8" ?>
<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="test.xsd">
<item>Nothing</item>
<item>Numbers
<one>1</one>
<two>2</two>
</item>
<item>Letters
<a>A</a>
<b>B</b>
<c>C</c>
</item>
</root>

Who's right, Xerces or me? Thanks.
 
U

usenet

I have a schema that contains a choice of groups, and one of the groups
contains an empty sequence. I can validate an XML document and the
schema with some validators, but not Xerces. It says "Empty content not
valid for content model: '((one,two)|((a,b),c))', which indicates that
it is ignoring the "empty" group. I think Xerces is wrong, but I'm not
100% certain. What do you think?

The schema is:

<?xml version="1.0" ?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:group name="empty">
<xsd:sequence/>
</xsd:group>
...
<xsd:complexType name="list">
<xsd:sequence>
<xsd:element name="item" minOccurs="1" maxOccurs="3">
<xsd:complexType mixed="true">
<xsd:choice>
<xsd:group ref="empty"/>
<xsd:group ref="numbers"/>
<xsd:group ref="letters"/>
</xsd:choice>
</xsd:complexType>

I'm afraid I'm not sure of what the exact intent of the spec is here
either. But if you expand your empty group into your choice you get:

<xsd:choice>
<xsd:sequence/>
<xsd:group ref="numbers"/>
<xsd:group ref="letters"/>
</xsd:choice>

Hence there is nothing of substance in the empty group, and probably
why it ignores it.

If you want to allow an empty option, you could try:

<xsd:choice minOccurs="0">
<xsd:group ref="numbers"/>
<xsd:group ref="letters"/>
</xsd:choice>

HTH,

Pete.
--
=============================================
Pete Cordell
Tech-Know-Ware Ltd
for XML to C++ data binding visit
http://www.tech-know-ware.com/lmx
(or http://www.xml2cpp.com)
=============================================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top