views:

20

answers:

1

I have the following xsd

<xsd:complexType name="myID">
    <xsd:choice>
        <xsd:element name="testID" type="priv:testID"/>
        <xsd:sequence>
            <xsd:element name="newID" type="priv:newID"/>
            <xsd:element name="testID" type="priv:testID" minOccurs="0"/>
        </xsd:sequence>
    </xsd:choice>
</xsd:complexType>

Everything is under priv namespace. The problem is that it looks like that myID is a union. It might be a testID or a sequence with newID and testID. When I compile it with wsdl2h from gsoap I am taking the message:

Note: <xs:choice> with embedded <xs:sequence> or <xs:group> prevents the use of a union

Is the above XSD correct?

A: 

In general the XML type myID can be declared as you described. The conflict exist probably in connection with your definition of the types priv:testID and priv:testID which definition you not included. For example the schema

<?xml version="1.0" encoding="utf-8"?>
<xsd:schema targetNamespace="http://www.ok-soft-gmbh.com/xml/xsd/1.0/XMLSchema.xsd"
    elementFormDefault="qualified"
    xmlns:priv="http://www.ok-soft-gmbh.com/xml/xsd/1.0/XMLSchema.xsd"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
>
    <xsd:simpleType name="testID">
        <xsd:restriction base="xsd:string"/>
    </xsd:simpleType>
    <xsd:simpleType name="newID">
        <xsd:restriction base="xsd:string"/>
    </xsd:simpleType>
    <xsd:complexType name="myID">
        <xsd:choice>
            <xsd:element name="testID" type="priv:testID"/>
            <xsd:sequence>
                <xsd:element name="newID" type="priv:newID"/>
                <xsd:element name="testID" type="priv:testID" minOccurs="0"/>
            </xsd:sequence>
        </xsd:choice>
    </xsd:complexType>
    <xsd:element name="root" type="priv:myID"/>
</xsd:schema>

will be correct. So if an error exist, it is not in the part which you posted.

Oleg
@Oleg, Your XSD is more complete than mine. The question is "is it legal to nest a sequence in the xsd:choice"?
cateof
@cateof: Yes it is legal.
Oleg