Xerces doesn't like choice of empty group

Discussion in 'XML' started by Ray Lischner, Feb 21, 2007.

  1. Ray Lischner

    Ray Lischner Guest

    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.
    --
    Ray Lischner, Proteus Technologies
    Ray Lischner, Feb 21, 2007
    #1
    1. Advertising

  2. Ray Lischner

    Guest

    On 21 Feb, 03:41, Ray Lischner <> wrote:
    > 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)
    =============================================
    , Feb 21, 2007
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mickey Segal
    Replies:
    0
    Views:
    870
    Mickey Segal
    Feb 2, 2004
  2. Don Sykes
    Replies:
    3
    Views:
    676
    Christophe Vanfleteren
    Feb 25, 2004
  3. cvissy
    Replies:
    0
    Views:
    604
    cvissy
    Nov 16, 2004
  4. Patrick Kowalzick
    Replies:
    5
    Views:
    470
    Patrick Kowalzick
    Mar 14, 2006
  5. miles.jg
    Replies:
    16
    Views:
    868
    Alf P. Steinbach
    Nov 14, 2007
Loading...

Share This Page