XML Schema
http://www.w3.org/TR/xmlschema
XML schema é um vocabulário XML para
expressar regras de negócios (sobre os
dados).
Exemplo
<localização>
<latitude>32.904237</latitude>
<longitude>73.620290</longitude>
<incerteza unidades="metros">2</incerteza>
</localização>
° A localização precisa ser seguida de uma latitude e de uma
longitude e do grau de incerteza que envolve as medidas;
° A latitude precisa ser um decimal com um valor entre -90 e 90
° A longitude precisa ser um decimal com um valor entre -180 e 180
Validando os dados:
<localização>
<latitude>32.904237</latitude>
<longitude>73.620290</longitude>
<incerteza unidades="metros">2</incerteza>
</localização>
checar a latitude
checar a longitude
etc....
XML Schema
XML Schema
validator
Proposta do schema XML
Especificar a estrutura das instâncias dos documentos!
Definir o tipo de dados (datatype) de cada elemento/atributo!
Exemplo de um esquema Schema XML
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.books.org"
xmlns="http://www.books.org"
elementFormDefault="qualified">
<xsd:element name="BookStore">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="Book" minOccurs="1" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="Book">
XML Schema
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="Title" minOccurs="1" maxOccurs="1"/>
<xsd:element ref="Author" minOccurs="1" maxOccurs="1"/>
<xsd:element ref="Date" minOccurs="1" maxOccurs="1"/>
<xsd:element ref="ISBN" minOccurs="1" maxOccurs="1"/>
<xsd:element ref="Publisher" minOccurs="1" maxOccurs="1"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="Title" type="xsd:string"/>
<xsd:element name="Author" type="xsd:string"/>
<xsd:element name="Date" type="xsd:string"/>
<xsd:element name="ISBN" type="xsd:string"/>
<xsd:element name="Publisher" type="xsd:string"/>
</xsd:schema>
xsd =
BookStore.xsd
Definition
DTD equivalente ao Schema XML exemplificado
DTD de uma Livraria (BookStore)
<!ELEMENT BookStore (Book+)>
<!ELEMENT Book (Title, Author, Date, ISBN, Publisher)>
<!ELEMENT Title (#PCDATA)>
<!ELEMENT Author (#PCDATA)>
<!ELEMENT Date (#PCDATA)>
<!ELEMENT ISBN (#PCDATA)>
<!ELEMENT Publisher (#PCDATA)>
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.books.org"
xmlns="http://www.books.org"
<!ELEMENT BookStore (Book+)>
elementFormDefault="qualified">
<xsd:element name="BookStore">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="Book" minOccurs="1" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="Book">
<!ELEMENT Book (Title, Author, Date,
<xsd:complexType>
<xsd:sequence>
ISBN, Publisher)>
<xsd:element ref="Title" minOccurs="1" maxOccurs="1"/>
<xsd:element ref="Author" minOccurs="1" maxOccurs="1"/>
<xsd:element ref="Date" minOccurs="1" maxOccurs="1"/>
<xsd:element ref="ISBN" minOccurs="1" maxOccurs="1"/>
<xsd:element ref="Publisher" minOccurs="1" maxOccurs="1"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="Title" type="xsd:string"/>
<xsd:element name="Author" type="xsd:string"/>
<xsd:element name="Date" type="xsd:string"/>
<xsd:element name="ISBN" type="xsd:string"/>
<xsd:element name="Publisher" type="xsd:string"/>
</xsd:schema>
<!ELEMENT Title (#PCDATA)>
<!ELEMENT Author (#PCDATA)>
<!ELEMENT Date (#PCDATA)>
<!ELEMENT ISBN (#PCDATA)>
<!ELEMENT Publisher (#PCDATA)>
Declaração de elementos:
<xsd:element name="
name" type=" type" minOccurs="int " maxOccurs="int "/>
Tipo simples
(xsd:string) ou
complexo.
Inteiro não
negativo.
Inteiro não negativo ou
‘unbounded’.
Alternativa
name" type="xsd:string" />
<xsd:element name="
Default: minOccurs=1 e maxOccurs=1
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.books.org"
xmlns="http://www.books.org“elementFormDefault="qualified">
<xsd:element name="BookStore">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="Book" minOccurs="1" maxOccurs= "unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="Book">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="Title" minOccurs="1" maxOccurs="1"/>
<xsd:element ref="Author" minOccurs="1" maxOccurs="1"/>
<xsd:element ref="Date" minOccurs="1" maxOccurs="1"/>
<xsd:element ref="ISBN" minOccurs="1" maxOccurs="1"/>
<xsd:element ref="Publisher" minOccurs="1" maxOccurs="1"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="Title" type="xsd:string"/>
<xsd:element name="Author" type="xsd:string"/>
<xsd:element name="Date" type="xsd:string"/>
<xsd:element name="ISBN" type="xsd:string"/>
<xsd:element name="Publisher" type="xsd:string"/>
</xsd:schema>
Declaração de elementos:
<xsd:element name="
name" type=" type" minOccurs="int " maxOccurs="int "/>
Tipo simples
(xsd:string) ou
complexo.
Inteiro não
negativo.
Inteiro não negativo ou
‘unbounded’.
Alternativa
<xsd:element name="name" minOccurs="int " maxOccurs="int">
<xsd:complexType>
...
</xsd:complexType>
</xsd:element>
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.books.org"
xmlns="http://www.books.org"elementFormDefault="qualified">
<xsd:element name="BookStore">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="Book" minOccurs="1" maxOccurs=
"unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="Book">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="Title" minOccurs="1" maxOccurs ="1"/>
<xsd:element ref="Author" minOccurs="1" maxOccur s="1"/>
<xsd:element ref="Date" minOccurs="1" maxOccurs ="1"/>
<xsd:element ref="ISBN" minOccurs="1" maxOccurs="1"/>
<xsd:element ref="Publisher" minOccurs="1" maxOccurs="1"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="Title" type="xsd:string"/>
<xsd:element name="Author" type="xsd:string"/>
<xsd:element name="Date" type="xsd:string"/>
<xsd:element name="ISBN" type="xsd:string"/>
<xsd:element name="Publisher" type="xsd:string"/>
</xsd:schema>
<!ELEMENT BookStore (Book+)>
<xsd:element name="BookStore">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="Book" minOccurs="1" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
<xsd:element>
<xsd:sequence>
Book +
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www+.w3.org/2001/XMLSchema"
targetNamespace="http://www.books.org"
xmlns="http://www.books.org" elementFormDefault="qualified">
<xsd:element name="BookStore">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="Book" minOccurs="1" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="Book">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="Title" minOccurs="1" maxOccurs ="1"/>
<xsd:element ref="Author" minOccurs="1" maxOccurs="1"/>
<xsd:element ref="Date" minOccurs="1" maxOccurs="1"/>
<xsd:element ref="ISBN" minOccurs="1" maxOccurs="1"/>
<xsd:element ref="Publisher" minOccurs="1" maxOccurs="1"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="Title" type="xsd:string"/>
<xsd:element name="Author" type="xsd:string"/>
<xsd:element name="Date" type="xsd:string"/>
<xsd:element name="ISBN" type="xsd:string"/>
<xsd:element name="Publisher" type="xsd:string"/>
</xsd:schema>
<!ELEMENT Book (Title, Author, Date, ISBN, Publisher)>
<xsd:element name="Book">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="Title" minOccurs="1" maxOccurs="1"/>
<xsd:element ref="Title" minOccurs="1" maxOccurs="1"/>
<xsd:element ref="Title" minOccurs="1" maxOccurs="1"/>
<xsd:element ref="Title" minOccurs="1" maxOccurs="1"/>
<xsd:element ref="Title" minOccurs="1" maxOccurs="1"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
Nomes para tipos
complexos
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.books.org"
xmlns="http://www.books.org"
elementFormDefault="qualified">
<xsd:element name="BookStore">
<xsd:complexType>
Sem
<xsd:sequence>
<xsd:element name="Book" maxOccurs="unbounded">nome
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Title" type="xsd:string"/>
<xsd:element name="Author" type="xsd:string"/> Declaração
<xsd:element name="Date" type="xsd:string"/>
Inline
<xsd:element name="ISBN" type="xsd:string"/>
<xsd:element name="Publisher" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
Nomes para tipos
complexos
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.books.org"
xmlns="http://www.books.org"
elementFormDefault="qualified">
<xsd:element name="BookStore">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Book" type="BookPublication" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
Vantagem:
<xsd:complexType name="BookPublication">
reutilização!
<xsd:sequence>
<xsd:element name="Title" type="xsd:string"/>
<xsd:element name="Author" type="xsd:string"/>
<xsd:element name="Date" type="xsd:string"/>
<xsd:element name="ISBN" type="xsd:string"/>
<xsd:element name="Publisher" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.books.org"
xmlns="http://www.books.org"
elementFormDefault="qualified">
<xsd:simpleType name="ISBNType">
<xsd:restriction base="xsd:string">
<xsd:pattern value="\d{1}-\d{5}-\d{3}-\d{1}"/>
<xsd:pattern value="\d{1}-\d{3}-\d{5}-\d{1}"/>
<xsd:pattern value="\d{1}-\d{2}-\d{6}-\d{1}"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:element name="BookStore">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Book" maxOccurs="unbounded">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Title" type="xsd:string"/>
<xsd:element name="Author" type="xsd:string"/>
<xsd:element name="Date" type="xsd:gYear"/>
<xsd:element name="ISBN" type="ISBNType"/>
<xsd:element name="Publisher" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
Tipo de dados do
usuário
Definição de um
novo tipo de dados
Declaração de ISBN
como do tipo
ISBNType
Outros Exemplos
<xsd:simpleType name="TelephoneNumber">
<xsd:restriction base="xsd:string">
<xsd:length value="8"/>
<xsd:pattern value="\d{3}-\d{4}"/>
</xsd:restriction>
</xsd:simpleType>
Restringe um tipo string a no máximo 8 caracteres, seguindo
um padrão: 3 dígitos seguido por um traço (-) e mais 4
dígitos.
Outros Exemplos
<xsd:simpleType name="shape">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="circle"/>
<xsd:enumeration value="triangle"/>
<xsd:enumeration value="square"/>
</xsd:restriction>
</xsd:simpleType>
Restringe um tipo string aos valores ‘circle’, ‘triangle’ e
‘square’.
Outros Exemplos
<xsd:simpleType name= "EarthSurfaceElevation">
<xsd:restriction base="xsd:integer">
<xsd:minInclusive value="-1290"/>
<xsd:maxInclusive value="29035"/>
</xsd:restriction>
</xsd:simpleType>
Restringe um tipo integer a um valor mínimo igual a -1290 e
máximo igual a 29035.
Resumo de declaração de Elementos
1
name"
<xsd:element name="
type="
type" minOccurs="int
" maxOccurs="int "/>
2
<xsd:element name="
name" minOccurs="int " maxOccurs="int ">
<xsd:complexType>
...
</xsd:complexType>
</xsd:element>
3
<xsd:element name="name" minOccurs="
int" maxOccurs="
int ">
<xsd:simpleType>
<xsd:restriction base="type">
...
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
Tipos Derivados
Formam uma subclasse de tipos complexos
1. Derivados por extensão: estendem o tipo complexo pai com mais
elementos
2. Derivados por restrição: criam um tipo que é um subconjunto do
tipo base.
2.1. Redefinir um elemento tipo base para ter uma restrição
sobre os valores possíveis;
2.2. OU redefinir um elemento tipo base para ter uma restrição
sobre o número de ocorrências;
<?xml version="1.0"?>
Derivando por extensão:
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.books.org"
xmlns="http://www.books.org"
elementFormDefault="qualified">
<xsd:complexType name="
Publication">
<xsd:sequence>
<xsd:element name="Title" type="xsd:string" maxOccurs="unbounded"/>
<xsd:element name="Author" type="xsd:string" maxOccurs="unbounded"/>
<xsd:element name="Date" type="xsd:gYear"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="
BookPublication">
<xsd:complexContent>
<xsd:extension base="Publication"
>
<xsd:sequence>
<xsd:element name="ISBN" type="xsd:string"/>
<xsd:element name="Publisher" type="xsd:string"/>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:element name="BookStore">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="
Book" type="BookPublication"
maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
BookPublication
estende a
Publication
<xsd:complexType name="Publication">
<xsd:sequence>
<xsd:element name="Title" type="xsd:string" maxOccurs="unbounded"/>
<xsd:element name="Author" type="xsd:string" maxOccurs="unbounded"/>
<xsd:element name="Date" type="xsd:gYear"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="BookPublication">
<xsd:complexContent>
<xsd:extension base="Publication" >
<xsd:sequence>
<xsd:element name="ISBN" type="xsd:string"/>
<xsd:element name="Publisher" type="xsd:string"/>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
O tipo Publication passa a ter 05 elementos!
ISBN
Title
Date
Author
Publication
BookPublication
Publisher
Derivando por restrição:
<xsd:complexType name="Publication">
<xsd:sequence>
<xsd:element name="Title" type="xsd:string"
maxOccurs="unbounded"/>
<xsd:element name="Author" type="xsd:string"
maxOccurs="unbounded" />
<xsd:element name="Date" type="xsd:gYear"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name= "SingleAuthorPublication">
<xsd:complexContent>
<xsd:restrictionbase="Publication" >
<xsd:sequence>
<xsd:element name="Title" type="xsd:string" maxOccurs="unbounded"/>
<xsd:element name="Author"
type="xsd:string"/>
<xsd:element name="Date"
type="xsd:gYear"/>
</xsd:sequence>
</xsd:restriction>
</xsd:complexContent>
</xsd:complexType>
Note que SingleAuthorPublication tem apenas três elementos e o elemento
Author aparecerá apenas 1 vez!
Declaração de Atributos
<!ELEMENT BookStore (Book)+>
<!ELEMENT Book (Title, Author+, Date, ISBN, Publisher)>
<!ATTLIST Book
Category (autobiography | non fiction
- | fiction) #REQUIRED
InStock (true | false) "false"
Reviewer CDATA " ">
<!ELEMENT Title (#PCDATA)>
<!ELEMENT Author (#PCDATA)>
<!ELEMENT Date (#PCDATA)>
<!ELEMENT ISBN (#PCDATA)>
<!ELEMENT Publisher (#PCDATA)>
<!ELEMENT Month (#PCDATA)>
<!ELEMENT Year (#PCDATA)>
BookStore.dtd
Declaração de Atributos
1.
<xsd:attribute name="nome" type="tipo simples" use="forma de uso"
default/fixed="valor"/>
2.
xsd:string
required
xsd:integer
xsd:boolean
...
optional
Obs.:se for usar
valor default, não
usar a opção "use"
prohibited
<xsd:attribute name="nome" type="tipo simples" default/fixed="valor"/>
<xsd:simpleType>
<xsd:restriction base=" tipo simples" >
<xsd:facetvalue="valor”/>
...
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
<xsd:element name="BookStore">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Book" maxOccurs="unbounded">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Title" type="xsd:string"/>
<xsd:element name="Author" type="xsd:string" maxOccurs="unbounded"/>
<xsd:element name="Date" type="xsd:string"/>
<xsd:element name="ISBN" type="xsd:string"/>
<xsd:element name="Publisher" type=" xsd:string"/>
</xsd:sequence>
<xsd:attributeGroup ref="BookAttributes"/>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
Category (autobiography | non fiction | -fiction) #REQUIRED
</xsd:complexType>
</xsd:element>
<xsd:attributeGroup name="BookAttributes">
<xsd:attribute name="Category" use="required">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:enumeration value="autobiography"/>
<xsd:enumeration value="non fiction"/>
<xsd:enumeration value="fiction"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
InStock (true | false) "false"
<xsd:attribute name="InStock" type="xsd:boolean" default ="false"/>
<xsd:attribute name="Reviewer" type="xsd:string" default =" "/>Reviewer CDATA " "
</xsd:attributeGroup>
<xsd:attribute name="Category" use="required">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:enumeration value="non
fiction"/>
<xsd:enumeration value="autobiography"/>
-
<xsd:enumeration value="fiction"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
- Instâncias dos documentos têm que obrigatoriamente ter o atributo Categoria.
- Os atributos são sempre simples, ou seja, não podem ter elementos filhos.
Declarando o atributo no próprio elemento
<xsd:element name="Book" maxOccurs="unbounded">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Title" type="xsd:string"/>
<xsd:element name="Author" type="xsd:string"axOccurs="unbounde
m
<xsd:element name="Date" type="xsd:string"/>
<xsd:element name="ISBN" type="xsd:string"/>
<xsd:element name="Publisher" type="xsd:string
"/>
</xsd:sequence>
<xsd:attribute name="Category" use="required">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
phy"/>
<xsd:enumeration -value="autobiogra
<xsd:enumeration value="non
fiction"/>
<xsd:enumeration value="fiction"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
<xsd:attribute name="InStock" type="xsd:boolean"
ault="false"/>
def
<xsd:attribute name="Reviewer" type="xsd:string"
ault="
def "/>
</xsd:complexType>
</xsd:element>
XMLSchema Namespace
http://www.w3.org/2001/XMLSchema
complexType
element
sequence
schema
string
integer
boolean
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.books.org"
xmlns="http://www.books.org"
elementFormDefault="qualified">
<xsd:element name="BookStore">
Indica que os elementos
<xsd:complexType>
definidos por esse
<xsd:sequence>
esquema:
<xsd:element ref="Book" minOccurs="1" maxOccurs="unbounded"/>
- BookStore
</xsd:sequence>
- Book
</xsd:complexType>
- Title
</xsd:element>
- Author
<xsd:element name="Book">
<xsd:complexType>
- Date
<xsd:sequence>
- ISBN
<xsd:element ref="Title" minOccurs="1" maxOccurs="1"/>
- Publisher
<xsd:element ref="Author" minOccurs="1" maxOccurs="1"/>
estarão no namespace
<xsd:element ref="Date" minOccurs="1" maxOccurs="1"/>
http://www.books.org
<xsd:element ref="ISBN" minOccurs="1" maxOccurs="1"/>
<xsd:element ref="Publisher" minOccurs="1" maxOccurs="1"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="Title" type="xsd:string"/>
<xsd:element name="Author" type="xsd:string"/>
<xsd:element name="Date" type="xsd:string"/>
<xsd:element name="ISBN" type="xsd:string"/>
<xsd:element name="Publisher" type="xsd:string"/>
</xsd:schema>
Book Namespace (targetNamespace)
http://www.books.org (targetNamespace)
BookStore
Author
Book
Title
Publisher ISBN
Date
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.books.org"
xmlns="http://www.books.org"
elementFormDefault="qualified">
<xsd:element name="BookStore">
<xsd:complexType>
O namespace padrão é
<xsd:sequence>
http://www.books.org,
<xsd:element ref="Book" minOccurs="1" maxOccurs="unbounded"/>
que também é o
</xsd:sequence>
targetNamespace
</xsd:complexType>
</xsd:element>
<xsd:element name="Book">
Referência ao
<xsd:complexType>
elemento Book,
<xsd:sequence>
<xsd:element ref="Title" minOccurs="1" maxOccurs="1"/>
declarado no
<xsd:element ref="Author" minOccurs="1" maxOccurs="1"/>
namespace padrão
<xsd:element ref="Date" minOccurs="1" maxOccurs="1"/>
<xsd:element ref="ISBN" minOccurs="1" maxOccurs="1"/>
<xsd:element ref="Publisher" minOccurs="1" maxOccurs="1"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="Title" type="xsd:string"/>
<xsd:element name="Author" type="xsd:string"/>
<xsd:element name="Date" type="xsd:string"/>
<xsd:element name="ISBN" type="xsd:string"/>
<xsd:element name="Publisher" type="xsd:string"/>
</xsd:schema>
Tipos de dados primitivos
•
Primitive Datatypes
– string
– boolean
– decimal
– float
– double
– duration
– dateTime
– time
– date
– gYearMonth
– gYear
– gMonthDay
– gDay
– gMonth
– hexBinary
– base64Binary
– anyURI
– QName
– NOTATION
Note: 'T' is the date/time separator
•
Atomic, built-in
– "Hello World"
– {true, false, 1, 0}
– 7.08
– 12.56E3, 12, 12560, 0, -0, INF, -INF, NAN
– 12.56E3, 12, 12560, 0, -0, INF, -INF, NAN
– P1Y2M3DT10H30M12.3S
– format: CCYY-MM-DDThh:mm:ss
– format: hh:mm:ss.sss
– format: CCYY-MM-DD
– format: CCYY-MM
– format: CCYY
– format: --MM-DD
– format: ---DD (note the 3 dashes)
– format: --MM-– a hex string
– a base64 string
– http://www.xfront.com
– a namespace qualified name
– a NOTATION from the XML spec
INF = infinity
NAN = not-a-number
Tipos de dados primitivos (cont.)
•
Derived types
– normalizedString
– token
– language
– IDREFS
– ENTITIES
– NMTOKEN
– NMTOKENS
– Name
– NCName
– ID
– IDREF
– ENTITY
– integer
– nonPositiveInteger
– negativeInteger
– long
– int
– short
– byte
– nonNegativeInteger
– unsignedLong
– unsignedInt
– unsignedShort
– unsignedByte
– positiveInteger
•
Subtype of primitive datatype
– A string without tabs, line feeds, or carriage returns
–
String w/o tabs, l/f, leading/trailing spaces, consecutive spaces
–
–
–
–
–
any valid xml:lang value, e.g., EN, FR, ...
usado somente com atributos
usado somente com atributos
usado somente com atributos
usado somente com atributos
–
–
–
–
–
–
–
–
–
–
–
–
–
–
–
–
–
part (no namespace qualifier)
usado somente com atributos
usado somente com atributos
usado somente com atributos
456
infinito negativo a 0
infinito negativo a -1
-9223372036854775808 to 9223372036854775807
-2147483648 to 2147483647
-32768 to 32767
-127 to 128
0 to infinity
0 to 18446744073709551615
0 to 4294967295
0 to 65535
0 to 255
1 to infinity
Forma geral para a especificação de valores de novos
tipos
<xsd:simpleType name= "name">
<xsd:restriction base= "xsd:source">
<xsd:facet value= "value"/>
<xsd:facet value= "value"/>
…
</xsd:restriction>
</xsd:simpleType>
Facets:
- length
- minlength
- maxlength
- pattern
- enumeration
- totalDigits
- minInclusive
- maxInclusive
- minExclusive
- maxExclusive
...
Sources:
- string
- boolean
- number
- float
- double
- duration
- dateTime
- time
...