Xis-Curs 8: - Xs:all Indica Faptul Ca Elementele Care Vor Urma Pot Aparea in Orice Ordine, Cu Conditia Ca

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

XIS-CURS 8

XML Schema- continuare

Indicatorii XML Schema:


-Indicatori de ordine:xs:all, xs:choice, xs:sequence
-Indicatori de aparitie: maxOccurs, minOccurs
-Indicatori de grup: xs:group, xs:attributeGroup

1. Indicatorii de ordine
-xs:all indica faptul ca elementele care vor urma pot aparea in orice ordine, cu conditia ca
fiecare element sa apara o singura data. Acest indicator apare de obicei ca descendent
direct pentru urmatoarele elemente: xs:group, xs:complexType, xs:restriction, xs:extension.

Exemplu: Daca elementele NUME si PRENUME trebuie sa apara in elementul PERSOANA insa
ordinea nu conteaza, atunci avem:
<xs:element name="PERSOANA">
<xs:complexType>
<xs:all>
<xs:element name="NUME" type="xs:string"/>
<xs:element name="PRENUME" type="xs:string"/>
</xs:all>
</xs:complexType>
</xs:element>

-xs:choice indica faptul ca doar un element din cele care vor urma poate fi prezent in
continutul elementului definit. Acest indicator apare de obicei ca descendent direct pentru
urmatoarele elemente: xs:group, xs:sequence, xs:complexType, xs:restriction, xs:extension.

<xs:element name="CARTE">
<xs:complexType>
<xs:choice>
<xs:element name="AUTOR" type="persoana"/>
<xs:element name="EDITOR" type="persoana"/>
</xs:choice>
</xs:complexType>
</xs:element>

-xs:sequence indica faptul ca elementele care vor urma apar secvential. Atata timp cat se
respecta aceasta regula, oricare dintre elemente poate salipseasca sau sa apara de un
numar nelimitat de ori. Acest indicator apare de obicei ca descendent direct pentru
urmatoarele elemente: xs:group, xs:choice, xs:complexType, xs:restriction, xs:extension.
<xs:element name="PERSOANA">
<xs:complexType>
<xs:sequence>
<xs:element name="NUME" type="xs:string"/>
<xs:element name="PRENUME" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>

2.Indicatorii de aparitie
-sunt reprezentati de atributele minOccurs si maxOccurs. Acestia au rolul de a indica cu
exactitate o valoare sau un interval care reprezinta numarul minim sau maxim de aparitii
acceptate ale unui element, secventa de elemente sau grup de elemente.

Indicator maxOccurs specifica numarul maxim de aparitii pentru un element:

<xs:element name="PERSOANA">
<xs:complexType>
<xs:sequence>
<xs:element name="NUME" type="xs:string"/>
<xs:element name="NUME-COPIL" type="xs:string" maxOccurs="5"/>
</xs:sequence>
</xs:complexType>
</xs:element>

In exemplu anterior elementul NUME-COPIL trebuie sa apara cel putin odata (valoarea implicita
pentru minOccurs este 1 implicit) si de maxim 5 ori in secventa ce descrie elementul
PERSOANA.

Indicator minOccurs specifica numarul minim de aparitii pentru un element:

<xs:element name="PERSOANA">
<xs:complexType>
<xs:sequence>
<xs:element name="NUME" type="xs:string"/>
<xs:element name="NUME-COPIL" type="xs:string" minOccurs="0"
maxOccurs="5"/>
</xs:sequence>
</xs:complexType>
</xs:element>

In exemplu anterior elementul NUME-COPIL poate sa nu apara deloc sau de maxim 5 ori in
secventa ce descrie elementul PERSOANA.
Observatie:
Pentru toate tipurile de indicatori de grupare sau ordine (any, all, choice, sequence, group)
valoarea implicita pentru maxOccurs and minOccurs este 1!

3.Indicatorii de grupare
-pentru elemente: <xs:group name=”nume”>...</xs:group>

in cadrul unui grup putem defini elemente all, choice, or sequence.

Exemplu: Sa presupunem ca dorim sa definim un grup cu nume "GRUP-PERSOANA", ce


defineste grupul de elemente ce trebuie sa apara exact intr-o ordine specificata. Atunci avem:

<xs:group name="GRUP-PERSOANA">
<xs:sequence>
<xs:element name="NUME" type="xs:string"/>
<xs:element name="PRENUME" type="xs:string"/>
<xs:element name="DATA-NASTERE" type="xs:date"/>
</xs:sequence>
</xs:group>

Ulterior ne putem referi la acel grup in cadrul altui grup sau in cadrul definirii tip complex astfel:

<xs:element name="PERSOANA" type="INFO-PERSOANA"/>


<xs:complexType name="INFO-PERSOANA">
<xs:sequence>
<xs:group ref="GRUP-PERSOANA"/>
<xs:element name="TARA" type="xs:string"/>
</xs:sequence>
</xs:complexType>

-pentru atribute: <xs:attributeGroup name=”nume”>...</xs:attributeGroup>

Exemplu: Sa presupunem ca dorim sa definim un grup cu nume "GRUP-PERSOANA", ce


defineste grupul de elemente ce trebuie sa apara exact intr-o ordine specificata. Atunci avem:

<xs:attributeGroup name="GRUP-PERSOANA">
<xs:attribute name="nume" type="xs:string"/>
<xs:attribute name="prenume" type="xs:string"/>
<xs:attribute name="data-nasterii" type="xs:date"/>
</xs:attributeGroup>

Ulterior ne putem referi la acel grup in cadrul altui grup sau in cadrul definirii tip complex astfel:
<xs:element name="PERSOANA" type="INFO-PERSOANA"/>
<xs:complexType name="INFO-PERSOANA">
<xs:attributeGroup ref="GRUP-PERSOANA">
</xs:complexType>

Exemplu

Sa consideram urmatorul document XML ce isi propune sa reprezinte un ordin de plata:

<?xml version="1.0" encoding="ISO-8859-1"?>


<shiporder orderid="889923" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="shiporder.xsd">
<orderperson>John Smith</orderperson>
<shipto>
<name>Ola Nordmann</name>
<address>Langgt 23</address>
<city>4000 Stavanger</city>
<country>Norway</country>
</shipto>
<item>
<title>Empire Burlesque</title>
<note>Special Edition</note>
<quantity>1</quantity>
<price>10.90</price>
</item>
<item>
<title>Hide your heart</title>
<quantity>1</quantity>
<price>9.90</price>
</item>
</shiporder>

Cerinta: Creati o schema XML atasata acestui document .

You might also like