0
votes

I have a created the below schema where product is a array , but the XSD validation(in eclipse) says maxOccurs="unbounded" minOccurs="0" cannot be used at the root element. So how to represent this structure in XSD. Below is how my XSD looks.

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element maxOccurs="unbounded" minOccurs="0" name="product">
        <xs:complexType>
            <xs:sequence>
                <xs:element minOccurs="1" name="id" type="xs:decimal"/>
                <xs:element minOccurs="1" name="name" type="xs:string"/>
                <xs:element minOccurs="1" name="price">
                    <xs:simpleType>
                        <xs:restriction base="xs:decimal"/>
                    </xs:simpleType>
                </xs:element>
                <xs:element maxOccurs="unbounded" minOccurs="0" name="tags" type="xs:string"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>
1
Please see the comprehensive answer I wrote to a nearly identical question asked just moments before yours. Thanks. - kjhughes

1 Answers

0
votes

To be well formed XML the document must have exactly one root-level element, so the easiest approach is to have a single root container element called something like products which in turn has zero-or-more product elements as its children.