Byron Claiborne
Byron Claiborne

Reputation: 215

XML schema issue: Repeating Element not repeating

I have a pretty standard xml schema defining an element called "part" that should repeat.

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:element name="part">
  <xs:complexType>
   <xs:sequence>
   <xs:element name="part_number" type="xs:string"/>
   <xs:element name="price" type="xs:decimal"/>
  </xs:sequence>
 </xs:complexType>
</xs:element>

</xs:schema>

problem is, when I use this schema to export a price list I get this:

<?XML version="1.0" encoding="UTF-8" standalone="yes"?>
<part>
<part_number>10-000</part_number>
<price>151.8</price>
</part>

When I want mulitple <part> elements. Where am I messing up in the schema?

Upvotes: 1

Views: 4932

Answers (2)

Johan Larsson
Johan Larsson

Reputation: 17580

  <xs:element name="parts">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="part" maxOccurs="unbounded" minOccurs="0">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="part_number" type="xs:string"/>
              <xs:element name="price" type="xs:decimal"/>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>

http://www.w3schools.com/schema/schema_example.asp

Upvotes: 4

Nathan Villaescusa
Nathan Villaescusa

Reputation: 17629

Your element needs maxOccurs="unbounded" since the default for maxOccurs is 1.

<xs:element name="part" maxOccurs="unbounded">

Upvotes: 2

Related Questions