How to change XML Schema so that it will recognize repetitive element?
I am fairly new at XML and I have a problem with the schema.
Here's what I have inside the XML file:
<?xml version="1.0" encoding="utf-8" ?>
<Receipt>
<Customer>
<FullName>Sammy Stevan Djap</FullName>
<Address>Jalan Daan Mogot Raya No. 10</Address>
<Province>Sulawesi Utara</Province>
<City>Manado</City>
<ZipCode>95126</ZipCode>
<Telephone>62431862169</Telephone>
<Memo>Barang di kirim bareng - bareng</Memo>
</Customer>
<Order>
<Product>
<Name>Afduner Botol</Name>
<Unit>Botol</Unit>
<Quantity>10</Quantity>
<Price>4500</Price>
<Total>45000</Total>
</Product>
</Order>
</Receipt>
And this is what I have in the schema:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Receipt">
<xs:complexType>
<xs:sequence>
<xs:element name="Customer">
<xs:complexType>
<xs:sequence>
<xs:element name="FullName" type="xs:string" />
<xs:element name="Address" type="xs:string" />
<xs:element name="Province" type="xs:string" />
<xs:element name="City" type="xs:string" />
<xs:element name="ZipCode" type="xs:unsignedInt" />
<xs:element name="Telephone" type="xs:unsignedLong" />
<xs:element name="Memo" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Order">
<xs:complexType>
<xs:sequence>
<xs:element name="Product">
<xs:complexType>
<xs:sequence>
<xs:element name="Name" type="xs:string" />
<xs:element name="Unit" type="xs:string" />
<xs:element name="Quantity" type="xs:unsignedByte" />
<xs:element name="Price" type="xs:unsignedShort" />
<xs:element name="Total" type="xs:unsignedShort" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
My goal is actually to make an XML file that allows repetitive "Product" tag. F开发者_JAVA技巧or instance:
<?xml version="1.0" encoding="utf-8" ?>
<Receipt>
<Customer>
<FullName>Sammy Stevan Djap</FullName>
<Address>Jalan Daan Mogot Raya No. 10</Address>
<Province>Sulawesi Utara</Province>
<City>Manado</City>
<ZipCode>95126</ZipCode>
<Telephone>62431862169</Telephone>
<Memo>Barang di kirim bareng - bareng</Memo>
</Customer>
<Order>
<Product>
<Name>Afduner Botol</Name>
<Unit>Botol</Unit>
<Quantity>10</Quantity>
<Price>4500</Price>
<Total>45000</Total>
</Product>
<Product>
<Name>Alat Potong Keramik 3 in 1</Name>
<Unit>Buah</Unit>
<Quantity>5</Quantity>
<Price>205000</Price>
<Total>1025000</Total>
</Product>
</Order>
</Receipt>
Apparently my schema does not know that I will call "Product" tag repetitively. At the moment, my schema only allows 1 "Product" tag being called.
Hence, my question is do you guys know how can I change my schema so that it will allow me to add multiple "Product" tags inside the "Order" tag?
Add minOccurs="0"
and maxOccurs="unbounded"
to the <xs:element name="Product">
element. If you want at least one Product
, use minOccurs="1"
.
精彩评论