XML - tworzenie schematu XSD

0

Na podstawie tego dokumentu xml mam utworzyć schemat xsd, w którym:

"tax-id" powinien zawierać dokładnie 13 znaków
"postcode" powinien zawierać dokładnie 6 znaków
"type" może przyjąć wyłącznie wartość "goods" lub "service"
"currency" może przyjmować wartość "PLN", "EUR" lub "USD"
"unit-price" musi być wyrażony z dokładnością do dwóch miejsc dziesiętnych
"unit" może przyjmować wartości wartości: "kg","pcs","l" lub "m2"
"VAT" może przyjmować wartości 22, 7, 3 lub 0

XML

<?xml version="1.0" encoding="UTF-8"?> <invoices> <invoice no="234/2006" date="2006-10-24" ship-date="2006-10-24"> <seller tax-id="677-15-91-304"> <company>Marpol Ltd.</company> <address>ul. Bajeczna 15</address> <postcode>32-097</postcode> <city>Krakow</city> </seller> <buyer tax-id="677-15-91-304"> <surname>Brown</surname> <name>John</name> <address>Al. Pokoju 109</address> <postcode>00-912</postcode> <city>Warszawa</city> </buyer> <item type="goods"> <name>brick</name> <quantity unit="pcs">12600</quantity> <unit-price currency="PLN">0.26</unit-price> <vat>22</vat> </item> <item type="goods"> <name>cement</name> <quantity unit="kg">1420</quantity> <unit-price currency="PLN">3.50</unit-price> <vat>7</vat> </item> </invoice> <invoice no="75/FV/2006" date="2006-08-07" ship-date="2006-08-12"> <seller tax-id="821-00-21-777"> <company>Rowenta Ltd.</company> <address>ul. Kurczaby 394</address> <postcode>41-220</postcode> <city>Lublin</city> </seller> <buyer tax-id="223-77-12-567"> <company>Budopol Ltd.</company> <address>ul. Olszaniecka 3</address> <postcode>12-201</postcode> <city>Olsztyn</city> </buyer> <item type="goods"> <name>window</name> <quantity unit="pcs">172</quantity> <unit-price currency="PLN">420</unit-price> <vat>7</vat> </item> <item type="goods"> <name>emulsion paint</name> <quantity unit="l">47</quantity> <unit-price currency="PLN">35.20</unit-price> <vat>22</vat> </item> <item type="service"> <name>delivery</name> <quantity unit="pcs">1</quantity> <unit-price currency="PLN">950</unit-price> <vat>0</vat> </item> <item type="service"> <name>painting of external walls</name> <quantity unit="m2">140</quantity> <unit-price currency="PLN">37.20</unit-price> <vat>7</vat> </item> <item type="goods"> <name>moulding</name> <quantity unit="pcs">17</quantity> <unit-price currency="PLN">21</unit-price> <vat>22</vat> </item> <item type="goods"> <name>eco wallpaper adhesive</name> <quantity unit="pcs">8</quantity> <unit-price currency="PLN">47.2</unit-price> <vat>3</vat> </item> </invoice> </invoices>

XSD

<?xml version="1.0" encoding="UTF-8"?>

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

<xsd:element name="invoices">
xsd:complexType
xsd:sequence
<xsd:element minOccurs="1" maxOccurs="unbounded" type="invoice" name="invoice"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>

<xsd:complexType name="invoice">
xsd:sequence
<xsd:element name="seller" type="seller" minOccurs="1" maxOccurs="1" />
<xsd:element name="buyer" type="buyer" minOccurs="1" maxOccurs="1" />
<xsd:element name="item" type="item" minOccurs="1" maxOccurs="unbounded" />
</xsd:sequence>
<xsd:attribute name="no" type="xsd:string" />
<xsd:attribute name="date" type="xsd:date" />
<xsd:attribute name="ship-date" type="xsd:date" />
</xsd:complexType>

<xsd:simpleType name="price">
<xsd:restriction base="xsd:token">
<xsd:pattern value="[0-9]{3}-[0-9]{2}-[0-9]{2}-[0-9]{3}"/>
</xsd:restriction>
</xsd:simpleType>

<xsd:simpleType name="vat">
<xsd:restriction base="xsd:int">
<xsd:enumeration value="23" />
<xsd:enumeration value="7" />
<xsd:enumeration value="3" />
<xsd:enumeration value="0" />
</xsd:restriction>
</xsd:simpleType>

<xsd:simpleType name="unit">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="kg" />
<xsd:enumeration value="pcs" />
<xsd:enumeration value="l" />
<xsd:enumeration value="m2" />
</xsd:restriction>
</xsd:simpleType>

<xsd:simpleType name="currency">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="PLN" />
<xsd:enumeration value="EUR" />
<xsd:enumeration value="USD" />
</xsd:restriction>
</xsd:simpleType>

<xsd:simpleType name="itemType">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="goods"/>
<xsd:enumeration value="service"/>
</xsd:restriction>
</xsd:simpleType>

<xsd:simpleType name="postCode">
<xsd:restriction base="xsd:string">
<xsd:length value="6"/>
</xsd:restriction>
</xsd:simpleType>

<xsd:simpleType name="taxId">
<xsd:restriction base="xsd:token">
<xsd:pattern value="[0-9]{3}-[0-9]{2}-[0-9]{2}-[0-9]{3}"/>
</xsd:restriction>
</xsd:simpleType>

<xsd:complexType name="seller">
xsd:sequence
<xsd:element name="company" type="xsd:string" />
<xsd:element name="address" type="xsd:string" />
<xsd:element name="postcode" type="postCode" />
<xsd:element name="city" type="xsd:string" />
</xsd:sequence>
<xsd:attribute name="tax-id" type="taxId" />
</xsd:complexType>

<xsd:complexType name="buyer">
xsd:choice
xsd:sequence
<xsd:element name="surname" type="xsd:string" />
<xsd:element name="name" type="xsd:string" />
<xsd:element name="address" type="xsd:string" />
<xsd:element name="postcode" type="postCode" />
<xsd:element name="city" type="xsd:string" />
</xsd:sequence>
xsd:sequence
<xsd:element name="company" type="xsd:string" />
<xsd:element name="address" type="xsd:string" />
<xsd:element name="postcode" type="postCode" />
<xsd:element name="city" type="xsd:string" />
</xsd:sequence>
</xsd:choice>
<xsd:attribute name="tax-id" type="taxId" />
</xsd:complexType>

<xsd:complexType name="item">
xsd:sequence
<xsd:element name="name" type="xsd:string" />
<xsd:element name="quantity" type="quantityElement" />
<xsd:element name="unit-price" type="unitPriceElement" />
<xsd:element name="VAT" type="xsd:float" />
</xsd:sequence>
<xsd:attribute name="type" type="itemType" />
</xsd:complexType>

<xsd:complexType name="quantityElement">
xsd:simpleContent
<xsd:extension base="xsd:string">
<xsd:attribute name="unit" type="unit" />
</xsd:extension>
</xsd:simpleContent>
</xsd:complexType>

<xsd:complexType name="unitPriceElement">
xsd:simpleContent
<xsd:extension base="xsd:string">
<xsd:attribute name="currency" type="currency" />
</xsd:extension>
</xsd:simpleContent>
</xsd:complexType>

</xsd:schema>

Czy jest to zrobione we właściwy sposób?

0

Odśwież.

1 użytkowników online, w tym zalogowanych: 0, gości: 1