1 / 20

Gli schema W3C

Gli schema W3C. Estensione di tipi semplici, scelte fra più elementi, application profiles. Elementi vuoti. Senza attributi <xs:element name=“figura”/> Con attributi <xs:element name=“figura"> <xs:complexType> <xs:attribute name=“didascalia" use="optional" type=“xs:string” />

blake-chang
Télécharger la présentation

Gli schema W3C

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Gli schema W3C Estensione di tipi semplici, scelte fra più elementi, application profiles

  2. Elementi vuoti • Senza attributi <xs:element name=“figura”/> • Con attributi <xs:element name=“figura"> <xs:complexType> <xs:attribute name=“didascalia" use="optional" type=“xs:string” /> <xs:attribute name=“link” use=“optional” type=“anyUri”> </xs:complexType> </xs:element>

  3. Derivazione di tipi semplici • Restringimento • Enumerazione • Modelli (espressioni regolari) • Estensione

  4. Enumerazione: attributi con valori <xs:complexType name="STANZE"> <xs:sequence> <xs:element name="verso" type="xs:string" maxOccurs="unbounded"/> </xs:sequence> <xs:attribute name="tipo" use="optional" default="quartina“ type=“en1”/> </xs:complexType> <xs:simpleType name=“en1”> <xs:restriction base="xs:string"> <xs:enumeration value=“terzina"/> <xs:enumeration value=“distico"/> <xs:enumeration value=“quartina"/> </xs:restriction> </xs:simpleType> L’enumerazione di valori è una restrizione del tipo semplice xs:string

  5. Enumerazione: elementi con valori <xs:element name="titolo"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:enumeration value="I"/> <xs:enumeration value="II"/> </xs:restriction> </xs:simpleType> </xs:element> Con gli schema si possono specificare anche i valori di un elemento

  6. Modelli \d{numero di caratteri} \s spazio <xsd:simpleType name="paginazione"> <xsd:restriction base="xsd:string"> <xsd:pattern value="\d{1,4}-\d{1,4}"/> </xsd:restriction> </xsd:simpleType> Espressione regolare

  7. Elemento con testo e attributi con valori <xs:complexType name="STANZE"> <xs:sequence> <xs:element name="verso" type=“Versi" maxOccurs="unbounded"/> </xs:sequence> </xs:complexType> <xs:complexType name=“Versi”> <xs:simpleContent> <xs:extension base="xs:string"> <xs:attribute name="tipo" use=“required"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:enumeration value=“settenario"/> <xs:enumeration value=“endecasillabo"/> </xs:restriction> </xs:simpleType> </xs:attribute> </xs:extension> </xs:simpleContent> </xs:complexType> Esercizio 20  Esercizio 22 (a casa) Bisogna estendere xs:string per accogliere attributi Per i valori degli attributi si deve restringere xs:string Tipo anonimo!

  8. Scelte fra più elementi <xs:complexType name="STANZE“> <xs:sequence> <xs:choice> <xs:element name="verso" type="xs:string“ maxOccurs="unbounded"/> <xs:element name=“versetto” type="xs:string“ maxOccurs="unbounded"/> </xs:choice> </xs:sequence> </xs:complexType>

  9. Mixed Content model <xs:complexType name="STANZE“ mixed=“true”> <xs:sequence> <xs:element name="verso" type="xs:string maxOccurs="unbounded"/> <xs:element name=“versetto” type="xs:string“ maxOccurs="unbounded"/> </xs:sequence> </xs:complexType>

  10. Mixed content model 2 <xs:complexType name="STANZE“ mixed=“true”> <xs:sequence> <xs:choice> <xs:sequence> <xs:element name="verso" type="xs:string“ maxOccurs="unbounded"/> <xs:element name=“versetto” type="xs:string“ maxOccurs="unbounded"/> </xs:sequence> <xs:sequence> <xs:element name=“versetto” type="xs:string“ maxOccurs="unbounded"/> <xs:element name="verso" type="xs:string“ maxOccurs="unbounded"/> </xs:sequence> </xs:choice> </xs:sequence> </xs:complexType>

  11. Mixed content Model 3: finalmente! <xs:complexType name="STANZE“ mixed=“true”> <xs:sequence> <xs:choicemaxOccurs="unbounded" minOccurs="0"> <xs:element name="verso" type="xs:string“ maxOccurs="unbounded"/> <xs:element name=“versetto” type="xs:string“ maxOccurs="unbounded"/> </xs:choice> </xs:sequence> </xs:complexType> Equivale a (#PCDATA|verso|versetto)*

  12. L’ordine degli elementi • sequence: ordine obbligatorio • choice: scelta fra più elementi • all: un qualsiasi ordine NOVITA! <xsd:complexType name="NTypo"> <xsd:all> <xsd:element name="luogoEd" type="xsd:string"/> <xsd:element name="editore" type="xsd:string"/> <xsd:element name="annoEd" type="xsd:gYear"/> </xsd:all> </xsd:complexType>

  13. Elementi e attributi qualificati • L’elemento root dello schema • <xs:schema xmlns:xs=http://www.w3.org/2001/XMLSchema • elementFormDefault="qualified" • attributeFormDefault="unqualified" • > Gli elementi dovranno essere preceduti da xs: Gli attributi no!

  14. Target namespace • Nell’elemento root si può anche: • definire qual’è il namespace principale • definire se elementi e attributi dovranno esplicitare o no il namespace <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.iccu.sbn.it/biblio.xsl" targetNamespace="http://www.sito.it/biblio.xsd" elementFormDefault="unqualified" attributeFormDefault="unqualified"> Se c’è si riferiscono al target namespace

  15. Il file 1. Non qualificato <bibliografia xmlns="http://www.sito.it/biblio.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.iccu.sbn.it/biblio.xsd"> <!-- qui il documento --> </bibliografia> 2. Qualificato <bib:bibliografia xmlns:bib="http://www.sito.it/biblio.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.iccu.sbn.it/biblio.xsd"> <!-- qui il documento --> </bib:bibliografia>

  16. Includere frammenti di schema Quando lo schema è grosso o si occupa di più argomenti si può spezzare in più file: <xs:include schemaLocation="biblio2.xsd"/>

  17. Importare altri namespace <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.sito.it/biblio.xsd" targetNamespace="http://www.sito.it/biblio.xsd" xmlns:dc="http://purl.org/dc/elements/1.1/" elementFormDefault="qualified" attributeFormDefault="unqualified" > <!-- ecc. --> <xsd:import namespace="http://purl.org/dc/elements/1.1/" schemaLocation="simpledc20020312.xsd"/> <xs:complexType name="VERSI"> <xs:sequence> <xs:element ref="dc:title"/> <xs:element name="stanza" type="STANZE" maxOccurs="unbounded"/> </xs:sequence> </xs:complexType> <xsd:schema> ref e non name

  18. Dublin Core • Schema di metadati descrittivi per identificare una risorsa. Comprende: • title • creator • publisher • date

  19. Application profiles • schema costituito da elementi recuperati da uno o più namespace combinati insieme dagli implementatori e ottimizzati per un particolare applicazione • Si possono combinare uno o più namespace • Non si possono introdurre nuovi elementi • Si possono specificare i valori degli elementi • Si possono raffinare le definizioni standard  Esercizio 21

  20. Annotazioni • <xsd:annotation> si usa per documentare gli schema, sia per gli umonai che per le macchine • <xsd:documentation> documentazione per gli umani • <xsd:appinfo> documentazione per le applicazioni <xsd:annotation> <xsd:documentation xml:lang="it"> Schema per la creazione di bibliografie <!-- ricordarsi di spiegare meglio questo punto --> </xsd:documentation> </xsd:annotation>

More Related