0% found this document useful (0 votes)
51 views16 pages

XML Schema: Processamento Estruturado de Documentos 2001 by JCR

The document describes XML Schema and its capabilities for structuring XML documents. It provides examples of using XML Schema to define complex data types for elements like poems, which have a title, author, date, and body structure made of verses grouped in stanzas. It also demonstrates defining simple types by restricting primitive types and using facets like enumeration, as well as defining elements and attributes with constraints. The goal is to validate XML documents against the defined schema structure and data types.

Uploaded by

Marcio Chiaveli
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views16 pages

XML Schema: Processamento Estruturado de Documentos 2001 by JCR

The document describes XML Schema and its capabilities for structuring XML documents. It provides examples of using XML Schema to define complex data types for elements like poems, which have a title, author, date, and body structure made of verses grouped in stanzas. It also demonstrates defining simple types by restricting primitive types and using facets like enumeration, as well as defining elements and attributes with constraints. The goal is to validate XML documents against the defined schema structure and data types.

Uploaded by

Marcio Chiaveli
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 16

jcr - ped2001 - 1 25-11-2001

XML Schema
Processamento Estruturado de
Documentos 2001
By jcr
jcr - ped2001 - 2 25-11-2001
Motivao
Sintaxe XML
Suporte para NameSpaces
data types, abstract data types, references.
reuse, extension, restriction, ...
jcr - ped2001 - 3 25-11-2001
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="poema">
<xs:complexType>
<xs:sequence>
<xs:element name="titulo" type="xs:string"/>
<xs:element name="autor" type="xs:string"/>
<xs:element name="data" type="xs:string"/>
<xs:element name="corpo" type="Tcorpo"/>
</xs:sequence>
<xs:attribute name="tipo"
type="xs:string"
use=optional"
default="soneto"/>
</xs:complexType>
</xs:element>
... </xs:schema>
Exemplo: O Poema
<xs:complexType name="Tcorpo">
<xs:sequence>
<xs:element name="quadra" type="Tquadra"/>
<xs:element name="quadra" type="Tquadra"/>
<xs:element name="terno" type="Tterno"/>
<xs:element name="terno" type="Tterno"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="Tquadra">
<xs:sequence>
<xs:element name="verso" type="Tverso"/>
<xs:element name="verso" type="Tverso"/>
<xs:element name="verso" type="Tverso"/>
<xs:element name="verso" type="Tverso"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="Tterno">
<xs:sequence>
<xs:element name="verso" type="Tverso"/>
<xs:element name="verso" type="Tverso"/>
<xs:element name="verso" type="Tverso"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="Tverso" mixed="true">
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="nome" type="xs:string"/>
<xs:element name="lugar" type="xs:string"/>
</xs:choice>
</xs:complexType>
jcr - ped2001 - 4 25-11-2001
Tipos Primitivos
String
Float
Decimal
Date
...
<xs:element name="nome" type="xs:string"/>
<xs:element name="lugar" type="xs:string"/>
jcr - ped2001 - 5 25-11-2001
Tipos Derivados
Derivam dos tipos primitivos
integer (decimal), long (integer), ...
Por restrio
Por extenso
jcr - ped2001 - 6 25-11-2001
Simple and Complex Types
Os tipos de dados em XML Schema ou so simple ou
complex.
Um tipo simple um dos tipos bsicos: string, date,
float, double, timeDuration, ...
Um tipo simple restringe o texto que pode aparecer no
valor dum atributo ou no contedo dum elemento textual.
Um elemento que tenha atributos ou elementos filho do
tipo complex.
Um tipo complex restringe o contedo dum elemento
relativamente aos atributos e elementos filho que pode ter.

jcr - ped2001 - 7 25-11-2001
Exemplo: complex Type
<xs:complexType name="Tquadra">
<xs:sequence>
<xs:element name="verso" type="Tverso"/>
<xs:element name="verso" type="Tverso"/>
<xs:element name="verso" type="Tverso"/>
<xs:element name="verso" type="Tverso"/>
</xs:sequence>
</xs:complexType>
Tverso uma referncia a um complex type definido
algures no schema
Tquadra um complex type com nome (por oposio a
um annimo)
jcr - ped2001 - 8 25-11-2001
Scope dos elemento
Um elemento pode ser declarado como
global ou como local.
Um elemento global declarado como
sendo filho de <schema>.
Um elemento local declarado algures na
estrutura do Schema.
Os elementos globais podem ser
reutilizados por referncia.
jcr - ped2001 - 9 25-11-2001
Elementos globais
<xs:element name="poema">
<xs:complexType>
<xs:sequence>
<xs:element name="titulo" type="xs:string"/>
<xs:element name="autor" type="xs:string"/>
<xs:element name="data" type="xs:string"/>
<xs:element name="corpo">
<xs:complexType>
<xs:sequence>
<xs:element ref = "Quadra"/>
<xs:element ref = "Quadra"/>
<xs:element ref = "Terno"/>
<xs:element ref = "Terno"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name=quadra>
<xs:complexType>
<xs:sequence>
<xs:element ref="verso"/>
<xs:element ref="verso"/>
<xs:element ref="verso"/>
<xs:element ref="verso"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<?xml version=1.0 encoding=iso-8859-1?>
<quadra>
<verso>Olha,<nome>Daisy</nome>: quando eu morrer tu hs-de</verso>
<verso>dizer aos meus amigos a de <nome>Londres</nome>,</verso>
<verso>embora no o sintas, que tu escondes</verso>
<verso>a grande dor da minha morte. Irs de</verso>
</quadra>
Instncia Vlida
jcr - ped2001 - 10 25-11-2001
Cardinalidade
<xs:complexType name="Tquadra">
<xs:sequence>
<xs:element name="verso" type="Tverso
minOccurs="4" maxOccurs="4"/>
</xs:sequence>
</xs:complexType>
A cardinalidade pode ser restringida recorrendo aos
atributos: minOccurs e maxOccurs
jcr - ped2001 - 11 25-11-2001
Valores para elementos
<xs:element name=email" type=xs:string
[email protected]"/>
Valor por omisso
<xs:element name=supervisor" type=xs:string
fixed=Jos Carlos Ramalho"/>
Valor fixo
jcr - ped2001 - 12 25-11-2001
Atributos
Os atributos declaram-se recorrendo ao
elemento <attribute>
Um atributo sempre do tipo simple
<xs:attribute name="tipo"
type="xs:string"
use=optional"
default="soneto"/>
use: (optional | default | required | fixed )
jcr - ped2001 - 13 25-11-2001
Restrio de tipos primitivos
<xs:simpleType name=dia base = xs:integer>
<xs:minInclusive value=1/>
<xs:maxInclusive value=31/>
</xs:simpleType>
<xs:simpleType name=telefone base = xs:integer>
<xs:pattern value=253-\d{6}/>
</xs:simpleType>
Restrio de domnio
Restrio de formato
jcr - ped2001 - 14 25-11-2001
Restries ou facetas
minInclusive
maxInclusive
maxExclusive
Length
minLength
maxLength
Pattern
Enumeration
minExclusive
Precision
Scale
Encoding
Period
Duration
jcr - ped2001 - 15 25-11-2001
Restrio por enumerao
<xs:simpleType name=diaSemana base = xs:string>
<xs:enumeration value=Domingo/>
<xs:enumeration value=Segunda/>
<xs:enumeration value=Tera/>
<xs:enumeration value=Quarta/>
<xs:enumeration value=Quinta/>
<xs:enumeration value=Sexta/>
<xs:enumeration value=Sbado/>
</xs:simpleType>
jcr - ped2001 - 16 25-11-2001
Elementos vazios
<xs:element name="ref">
<xs:complexType>
<xs:attribute name="destino"
type="xs:string"
use="required"/>
</xs:complexType>
</xs:element>
<xs:element name="imagem">
<xs:complexType>
<xs:attribute name="path" type="xs:string"
use="required"/>
<xs:attribute name="formato" type="xs:string"
use="optional"/>
</xs:complexType>
</xs:element>

You might also like