0

I would like to have this behaviour : a complex element has got some elements (so it does not contains a sequence) but some of these elements have got "minoccurs" and/or "maxoccurs" defined. I tried to build such a file, and it looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:element name="nom_site">
    <xs:simpleType>
        <xs:restriction base="xs:string">
            <xs:length value="3" />
        </xs:restriction>
    </xs:simpleType>
</xs:element>
<xs:element name="nom_type">
    <xs:simpleType>
        <xs:restriction base="xs:string">
            <xs:length value="2" />
        </xs:restriction>
    </xs:simpleType>
</xs:element>

<xs:element name="sites">
    <xs:complexType>
        <xs:all>
            <xs:element name="site">
                <xs:complexType>
                    <xs:all>
                        <xs:element ref="nom_site"></xs:element>
                        <xs:element name="délai" type="xs:int"></xs:element>
                        <xs:element name="expéditeur" type="xs:string"></xs:element>
                        <xs:element name="message" type="xs:string"></xs:element>

                        <xs:element name="types" minOccurs="0" maxOccurs="1">
                            <xs:complexType>

                                <xs:all>
                                    <xs:element name="type">
                                        <xs:complexType>
                                            <xs:all>
                                                <xs:element ref="nom_type"></xs:element>
                                                <xs:element name="message" type="xs:string"></xs:element>
                                                <xs:element name="libellés" minOccurs="0"
                                                    maxOccurs="1">
                                                    <xs:complexType>
                                                        <xs:all>
                                                            <xs:element name="libellé">
                                                                <xs:complexType>
                                                                    <xs:all>
                                                                        <xs:element name="nom_lib" type="xs:string"></xs:element>
                                                                        <xs:element name="message" type="xs:string"></xs:element>
                                                                    </xs:all>
                                                                </xs:complexType>
                                                            </xs:element>
                                                        </xs:all>
                                                    </xs:complexType>
                                                </xs:element>
                                            </xs:all>
                                        </xs:complexType>
                                    </xs:element>
                                </xs:all>
                            </xs:complexType>
                        </xs:element>

                    </xs:all>
                </xs:complexType>
            </xs:element>
        </xs:all>
    </xs:complexType>
</xs:element>
</xs:schema>

but eclipse raise an error : under the "all" item, the cardinalities can only be "0" or "1"...

if my element connot contains "sequence" or "all", is there something else possible?

thanks,

olivier

Anders R. Bystrup
  • 15,729
  • 10
  • 59
  • 55
lolveley
  • 1,659
  • 2
  • 18
  • 34
  • I see nothing wrong with this schema. Are you validating a concrete XML file against it and getting validation errors? – Anders R. Bystrup Jan 28 '14 at 11:21
  • Saxon accepts the schema as valid. I don't see any cardinalities other than 0 and 1. Are you sure you are processing the schema you think you are? Is there are line number for the error? – Michael Kay Jan 28 '14 at 13:10

2 Answers2

0

I've loaded this into xml spy and it is valid and well formed according to that. Can't see any particuler issues.

Generates sample of:

<?xml version="1.0" encoding="UTF-8"?>
<!--Sample XML file generated by XMLSpy v2013 rel. 2 sp2 (http://www.altova.com)-->
<sites xsi:noNamespaceSchemaLocation="test.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <site>
        <nom_site>aaa</nom_site>
        <délai>0</délai>
        <expéditeur>String</expéditeur>
        <message>String</message>
        <types>
            <type>
                <nom_type>aa</nom_type>
                <message>String</message>
                <libellés>
                    <libellé>
                        <nom_lib>String</nom_lib>
                        <message>String</message>
                    </libellé>
                </libellés>
            </type>
        </types>
    </site>
</sites>

So some issue with eclipse or the way you are using the xsd maybe?

dethorpe
  • 511
  • 2
  • 9
0

ok, solved :

<xs:element name="sites">
<xs:complexType>
    <xs:sequence>
        <xs:element name="site" minOccurs="0" maxOccurs="unbounded">

I don't understand what my XSD file passes your applications.

lolveley
  • 1,659
  • 2
  • 18
  • 34