Notes sur l'introduction à XML - 3° partie, Notes de Méthodes mathématiques pour l'analyse numérique et l'optimisation
Francine88
Francine8826 février 2014

Notes sur l'introduction à XML - 3° partie, Notes de Méthodes mathématiques pour l'analyse numérique et l'optimisation

PDF (95 KB)
24 pages
1000+Numéro de visites
Description
Notes d’informatique sur l'introduction à XML - 3° partie. Les principaux thèmes abordés sont les suivants: Les schémas XML
20 points
Points de téléchargement necessaire pour télécharger
ce document
Télécharger le document
Aperçu3 pages / 24

Ceci c'est un aperçu avant impression

3 shown on 24 pages

Télécharger le document

Ceci c'est un aperçu avant impression

3 shown on 24 pages

Télécharger le document

Ceci c'est un aperçu avant impression

3 shown on 24 pages

Télécharger le document

Ceci c'est un aperçu avant impression

3 shown on 24 pages

Télécharger le document
chapitre 1_2_3

III. Les schémas XML: 5. Les éléments complexes

Extension d’un élément complexe Vous pouvez également baser un élément complexe sur un élément complexe existant et ajouter quelques éléments, comme ceci:

<xs:complexType name="personinfo"> <xs:sequence>

<xs:element name="firstname" type="xs:string"/> <xs:element name="lastname" type="xs:string"/>

</xs:sequence> </xs:complexType>

<xs:complexType name="fullpersoninfo"> <xs:complexContent>

<xs:extension base="personinfo"> <xs:sequence>

<xs:element name="address" type="xs:string"/> <xs:element name="city" type="xs:string"/> <xs:element name="country" type="xs:string"/>

</xs:sequence> </xs:extension>

</xs:complexContent> </xs:complexType>

<xs:element name="employee" type="fullpersoninfo"/>

20-09-2010 49

III. Les schémas XML: 6. Les éléments vides

Exemple: Code XML

<product prodid="1345" />

Définition 1: <xs:element name="product"> <xs:complexType> <xs:attribute name="prodid" type="xs:positiveInteger"/>

</xs:complexType> </xs:element>

Définition 2: <xs:complexType name="prodtype"> <xs:attribute name="prodid" type="xs:positiveInteger"/> </xs:complexType>

<xs:element name="product" type="prodtype"/>

20-09-2010 50

III. Les schémas XML:

7. Les éléments(types) mixtes

Exemple:

• Un élément complexe de type mixte peut contenir des attributs, des éléments, et de texte.

• Code XML <letter> Dear Mr.<name>John Smith</name>. Your order <orderid>1032</orderid> will be shipped on <shipdate>2001-07-13</shipdate>.

</letter>

20-09-2010 51

III. Les schémas XML: 7. Les éléments(types) mixtes

Exemple: Définition 1:

<xs:element name="letter"> <xs:complexType mixed="true">

<xs:sequence> <xs:element name="name" type="xs:string"/> <xs:element name="orderid" type="xs:positiveInteger"/> <xs:element name="shipdate" type="xs:date"/>

</xs:sequence> </xs:complexType>

</xs:element> • Définition 2:

<xs:complexType name="lettertype" mixed="true"> <xs:sequence>

<xs:element name="name" type="xs:string"/> <xs:element name="orderid" type="xs:positiveInteger"/> <xs:element name="shipdate" type="xs:date"/>

</xs:sequence> </xs:complexType>

<xs:element name="letter" type="lettertype"/>

20-09-2010 52

III. Les schémas XML: 8. Les indicateurs:

Les indicateurs d’ordre:

All Indicator The <all> indicator specifies that the child elements can appear in any order, and that each child element must occur only once: <xs:element name="person"> <xs:complexType>

<xs:all> <xs:element name="firstname" type="xs:string"/> <xs:element name="lastname" type="xs:string"/>

</xs:all> </xs:complexType>

</xs:element>

Note: When using the <all> indicator you can set the <minOccurs> indicator to 0 or 1 and the <maxOccurs> indicator can only be set to 1 (the <minOccurs> and <maxOccurs> are described later).

20-09-2010 53

III. Les schémas XML:

8. Les indicateurs:

Les indicateurs d’ordre:

Choice Indicator The <choice> indicator specifies that either one child element or another can occur:

<xs:element name="person"> <xs:complexType> <xs:choice> <xs:element name="employee" type="employee"/> <xs:element name="member" type="member"/>

</xs:choice> </xs:complexType>

</xs:element>

20-09-2010 54

III. Les schémas XML:

8. Les indicateurs:

Les indicateurs d’ordre:

Sequence Indicator The <sequence> indicator specifies that the child elements must appear in a specific order:

<xs:element name="person"> <xs:complexType> <xs:sequence> <xs:element name="firstname" type="xs:string"/> <xs:element name="lastname" type="xs:string"/>

</xs:sequence> </xs:complexType>

</xs:element>

20-09-2010 55

III. Les schémas XML:

8. Les indicateurs:

Les indicateurs d’occurrence:

Occurrence indicators are used to define how often an element can occur.

Note:

For all "Order" and "Group" indicators (any, all, choice, sequence, group name, and group reference) the default value for maxOccurs and minOccurs is 1.

<xs:element name="child_name" type="xs:string" maxOccurs="10" minOccurs="0"/>

20-09-2010 56

III. Les schémas XML: 8. Les indicateurs:

Les indicateurs de group:

Element Groups <xs:group name="persongroup"> <xs:sequence>

<xs:element name="firstname" type="xs:string"/> <xs:element name="lastname" type="xs:string"/> <xs:element name="birthday" type="xs:date"/>

</xs:sequence> </xs:group>

<xs:element name="person" type="personinfo"/>

<xs:complexType name="personinfo"> <xs:sequence>

<xs:group ref="persongroup"/> <xs:element name="country" type="xs:string"/>

</xs:sequence> </xs:complexType>

20-09-2010 57

III. Les schémas XML:

8. Les indicateurs:

Les indicateurs de group:

Attribute Groups <xs:attributeGroup name="personattrgroup"> <xs:attribute name="firstname" type="xs:string"/> <xs:attribute name="lastname" type="xs:string"/> <xs:attribute name="birthday" type="xs:date"/>

</xs:attributeGroup>

<xs:element name="person"> <xs:complexType> <xs:attributeGroup ref="personattrgroup"/>

</xs:complexType> </xs:element>

20-09-2010 58

III. Les schémas XML:

8. Les indicateurs:

Example:

Code XML: <?xml version="1.0" encoding="ISO-8859-1"?> <persons xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="family.xsd">

<person> <full_name>Hege Refsnes</full_name> <child_name>Cecilie</child_name>

</person> <person> <full_name>Tove Refsnes</full_name> <child_name>Hege</child_name> <child_name>Stale</child_name> <child_name>Jim</child_name> <child_name>Borge</child_name>

</person> <person> <full_name>Stale Refsnes</full_name>

</person>

</persons>

20-09-2010 59

III. Les schémas XML: 8. Les indicateurs:

Les indicateurs de group:

Schéma XML:

<?xml version="1.0" encoding="ISO-8859-1"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">

<xs:element name="persons"> <xs:complexType> <xs:sequence>

<xs:element name="person" maxOccurs="unbounded"> <xs:complexType> <xs:sequence> <xs:element name="full_name" type="xs:string"/> <xs:element name="child_name" type="xs:string" minOccurs="0" maxOccurs="5"/>

</xs:sequence> </xs:complexType>

</xs:element> </xs:sequence>

</xs:complexType> </xs:element>

</xs:schema>

20-09-2010 60

III. Les schémas XML: 9. L’élément <any>:

Utilité:

L'élément <any> nous permet d'étendre le document XML avec des éléments non spécifiés par le schéma.

Scéma family.sxd <?xml version="1.0" encoding="ISO-8859-1"?> <xs:schema xmlns:xs=http://www.w3.org/2001/XMLSchema elementFormDefault="qualified"> <xs:element name="person"> <xs:complexType>

<xs:sequence> <xs:element name="firstname" type="xs:string"/> <xs:element name="lastname" type="xs:string"/> <xs:any minOccurs="0"/>

</xs:sequence> </xs:complexType>

</xs:element>

20-09-2010 61

III. Les schémas XML:

9. L’élément <any>:

Scéma children.sxd <?xml version="1.0" encoding="ISO-8859-1"?> <xs:schema xmlns:xs=http://www.w3.org/2001/XMLSchema elementFormDefault="qualified">

<xs:element name="children"> <xs:complexType> <xs:sequence> <xs:element name="childname" type="xs:string" maxOccurs="unbounded"/>

</xs:sequence> </xs:complexType>

</xs:element>

</xs:schema>

20-09-2010 62

III. Les schémas XML: 9. L’élément <any>:

Le fichier family.xml <?xml version="1.0" encoding="ISO-8859-1"?>

<persons xmlns="http://www.microsoft.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:SchemaLocation="family.xsd children.xsd">

<person> <firstname>Hege</firstname> <lastname>Refsnes</lastname> <children>

<childname>Cecilie</childname> </children>

</person>

<person> <firstname>Stale</firstname> <lastname>Refsnes</lastname>

</person>

</persons>

20-09-2010 63

III. Les schémas XML: 10. L’élément <anyAttribute>:

Utilité:

The <anyAttribute> element enables to extend the XML document with attributes not specified by the schema. Scéma family.sxd <?xml version="1.0" encoding="ISO-8859-1"?> <xs:schema xmlns:xs=http://www.w3.org/2001/XMLSchema elementFormDefault="qualified"> <xs:element name="person"> <xs:complexType>

<xs:sequence> <xs:element name="firstname" type="xs:string"/> <xs:element name="lastname" type="xs:string"/>

</xs:sequence> <xs:anyAttribute/>

</xs:complexType> </xs:element>

20-09-2010 64

III. Les schémas XML:

10. L’élément <anyAttribute>:

Scéma attribute.sxd <?xml version="1.0" encoding="ISO-8859-1"?> <xs:schema xmlns:xs=http://www.w3.org/2001/XMLSchema elementFormDefault="qualified">

<xs:attribute name="gender"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:pattern value="male|female"/>

</xs:restriction> </xs:simpleType>

</xs:attribute>

</xs:schema>

20-09-2010 65

III. Les schémas XML: 10. L’élément <anyAttribute>:

Le fichier family.xml The XML file below (called "Myfamily.xml"), uses components from two different schemas; "family.xsd" and "attribute.xsd": <?xml version="1.0" encoding="ISO-8859-1"?>

<persons xmlns="http://www.microsoft.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:SchemaLocation="family.xsd attribute.xsd">

<person gender="female"> <firstname>Hege</firstname> <lastname>Refsnes</lastname>

</person>

<person gender="male"> <firstname>Stale</firstname> <lastname>Refsnes</lastname>

</person>

</persons>

20-09-2010 66

III. Les schémas XML: 11. Exercice:

Enoncé: Donner un schéma xml pour le fichier " shiporder.xml " suivant: <?xml version="1.0" encoding="ISO-8859-1"?> <shiporder orderid="889923" > <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>

20-09-2010 67

III. Les schémas XML: 11. Exercice:

Solution 1:

<?xml version="1.0" encoding="ISO-8859-1" ?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:element name="shiporder"> <xs:complexType>

<xs:sequence> <xs:element name="orderperson" type="xs:string"/> <xs:element name="shipto">

<xs:complexType> <xs:sequence>

<xs:element name="name" type="xs:string"/> <xs:element name="address" type="xs:string"/> <xs:element name="city" type="xs:string"/> <xs:element name="country" type="xs:string"/>

</xs:sequence> </xs:complexType>

</xs:element>

20-09-2010 68

III. Les schémas XML: 11. Exercice:

Solution 1:

<xs:element name="item" maxOccurs="unbounded"> <xs:complexType>

<xs:sequence> <xs:element name="title" type="xs:string"/> <xs:element name="note" type="xs:string" minOccurs="0"/> <xs:element name="quantity" type="xs:positiveInteger"/> <xs:element name="price" type="xs:decimal"/>

</xs:sequence> </xs:complexType>

</xs:element> </xs:sequence> <xs:attribute name="orderid" type="xs:string" use="required"/>

</xs:complexType> </xs:element>

</xs:schema>

20-09-2010 69

III. Les schémas XML: 11. Exercice:

Solution 2:

The previous design method is very simple, but can be difficult to read and maintain when documents are complex. The next design method is based on defining all elements and attributes first, and then referring to them using the ref attribute. Here is the new design of the schema file ("shiporder.xsd"): <?xml version="1.0" encoding="ISO-8859-1" ?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<!-- definition of simple elements --> <xs:element name="orderperson" type="xs:string"/> <xs:element name="name" type="xs:string"/> <xs:element name="address" type="xs:string"/> <xs:element name="city" type="xs:string"/> <xs:element name="country" type="xs:string"/> <xs:element name="title" type="xs:string"/> <xs:element name="note" type="xs:string"/> <xs:element name="quantity" type="xs:positiveInteger"/> <xs:element name="price" type="xs:decimal"/>

<!-- definition of attributes --> <xs:attribute name="orderid" type="xs:string"/>

20-09-2010 70

III. Les schémas XML:

11. Exercice:

Solution 2:

<!-- definition of complex elements -->

<xs:element name="shipto"> <xs:complexType> <xs:sequence> <xs:element ref="name"/> <xs:element ref="address"/> <xs:element ref="city"/> <xs:element ref="country"/>

</xs:sequence> </xs:complexType>

</xs:element>

<xs:element name="item"> <xs:complexType> <xs:sequence> <xs:element ref="title"/> <xs:element ref="note" minOccurs="0"/> <xs:element ref="quantity"/> <xs:element ref="price"/>

</xs:sequence> </xs:complexType>

</xs:element>

20-09-2010 71

III. Les schémas XML:

11. Exercice:

Solution 2:

<xs:element name="shiporder"> <xs:complexType> <xs:sequence> <xs:element ref="orderperson"/> <xs:element ref="shipto"/> <xs:element ref="item" maxOccurs="unbounded"/>

</xs:sequence> <xs:attribute ref="orderid" use="required"/>

</xs:complexType> </xs:element>

</xs:schema>

20-09-2010 72

commentaires (0)

Aucun commentaire n'a été pas fait

Écrire ton premier commentaire

Ceci c'est un aperçu avant impression

3 shown on 24 pages

Télécharger le document