Plan prezentacji Przedmiot: XML i jego zastosowania Dr inż. Stanisław Polak Akademia Górniczo - Hutnicza w Krakowie, Katedra Informatyki http://www.icsr.agh.edu.pl/~polak/ Wstęp Dokumenty i Schematy XML Definiowanie elementów i atrybutów Typy proste Grupy Symbole wieloznaczne Zewnętrzne Schematy Dr inż. Stanisław Polak 1 Przedmiot: XML i jego zastosowania Dr inż. Stanisław Polak Przedmiot: XML i jego zastosowania Wstęp Wstęp Ogólna charakterytyka XML Schema Zalety i wady Schematów XML XML Schema (Schemat XML, Schemat Rozszerzalnego Języka Znaczników) DTD++, zwykle z rozszerzeniem.xsd (od XML Schema Definition) Hierarchia elementów hierarchia klas obiektów Możliwości: Klasy obiektów Hierarchie, Typy danych, Ograniczenia, Związki Import Zalety Jest dokumentem XML Możliwość deklarowania typów danych Możliwość definiowania powtarzających się fragmentów modelu i odwoływania się do nich Obsługa przestrzeni nazw Wady Duży rozmiar Skomplikowana składnia Nie można definiować encji Dr inż. Stanisław Polak 3 Przedmiot: XML i jego zastosowania Dr inż. Stanisław Polak 4 Przedmiot: XML i jego zastosowania
Wstęp Dokumenty i Schematy XML Przykładowe DTD i odpowiadający mu Schemat XML Wiązanie Schematu z dokumentem XML 1 <? xml version=" 1.0 " e n c o d i n g="iso -8859 - "?> <p r a c o w n i k xmlns="http: //www.agh.edu.pl" x m l n s : x s i="http: //www.w3.org /001/ XMLSchema -instance " x s i : s c h e m a L o c a t i o n=" http: // www. agh. edu.pl pracownik. xsd "> 3 <i m i e>jan</ i m i e> 4 <n a z w i s k o>nowak</ n a z w i s k o> 5 <d a t a u r o d z e n i a> 6 <rok>1969</ rok> 7 <m i e s i a c>maj</ m i e s i a c> 8 <d z i e n>1</ d z i e n> 9 </ d a t a u r o d z e n i a> 10 <m i e j s c e p r a c y budynek="c1"/> 11 </ p r a c o w n i k> Przykładowy dokument XML Pusta przestrzeń nazw 1 <r o o t x s i : nonamespaceschemalocation=" correct_a. xsd " 3 xmlns="" 4 x m l n s : x s i="http: //www.w3.org /001/ XMLSchema - instance ">test 5 </ r o o t> Określona przestrzeń nazw 1 <f : r o o t x s i : schemalocation=" http://foo correct_b.xsd " 3 x m l n s : f=" http://foo " 4 x m l n s : x s i="http: //www.w3.org /001/ XMLSchema - instance " >test </ f : r o o t> 1 <x s : e l e m e n t name= "pracownik"> <x s :complextype> 1 <! ELEMENT pracownik ( imie, nazwisko, 3 <x s : s e q u e n c e> d a t a u r o d z e n i a, m i e j s c e p r a c y )> 4 <x s : e l e m e n t r e f=" imie "/> <! ELEMENT imie (#PCDATA) > 5 <x s : e l e m e n t r e f=" nazwisko "/> 3 <! ELEMENT n a z w i s k o (#PCDATA ) > 6 <x s : e l e m e n t r e f=" data_urodzenia "/> 4 <! ELEMENT d a t a u r o d z e n i a ( rok, m i e s i a c, d z i e n ) > 7 <x s : e l e m e n t r e f=" miejsce_pracy "/> 5 <! ELEMENT rok (#PCDATA ) > 8 </ x s :sequence> 6 <! ELEMENT m i e s i a c (#PCDATA ) > 9 </ x s:complextype> 7 <! ELEMENT d z i e n (#PCDATA ) > 10 </ x s :element> 8 <! ELEMENT m i e j s c e p r a c y EMPTY > 11 9 <! ATTLIST m i e j s c e p r a c y budynek CDATA #REQUIRED> 1 <x s : e l e m e n t name= "imie" t y p e=" xs:string "/> 13... DTD Fragment Schematu XML 1 <xsd:schema x m l n s : x s d=" http: // www.w3.org /001/ XMLSchema ">... 3 </ xsd:schema> correct A.xsd 1 <xsd:schema targetnamespace=" http://foo " x m l n s : x s d= "http: //www.w3.org /001/ XMLSchema ">... 3 </ xsd:schema> correct B.xsd Dr inż. Stanisław Polak 5 Przedmiot: XML i jego zastosowania Dr inż. Stanisław Polak 6 Przedmiot: XML i jego zastosowania Definiowanie elementów i atrybutów Definiowanie elementów i atrybutów Rodzaje typów elementów Definiowanie elementów i atrybutów Złożony Prosty 1 <AAA>xxx yyy</aaa> 1 <AAA/> 1 <AAA> <BBB>ZZZ</BBB> 3 <CCC>YYY</CCC> 4 </AAA> 1 <AAA xx= 1 >qwerty uiop</aaa> 1 <AAA>xxx yyy <BBB>ZZZ</BBB>aaa 3 </AAA> element simpletype complextype union restriction list complexcontent all choice attribute sequence simplecontent simpletype simpletype restriction attribute simpletype extension element attribute simpletype element element restriction attribute simpletype extension attribute simpletype Dr inż. Stanisław Polak 7 Przedmiot: XML i jego zastosowania Dr inż. Stanisław Polak 8 Przedmiot: XML i jego zastosowania
Definiowanie elementów i atrybutów Definiowanie elementów i atrybutów Definicje globalne Definicje lokalne www.w3.org /001/ XMLSchema - instance "> <BBB xx="1">zzz</bbb> 3 </AAA> <x s d : e l e m e n t name=" AAA "> 3... 4 <x s d : e l e m e n t ref =" BBB "/> 5... 6 </ x s d : e l e m e n t> 7 8 <xsd: element name=" BBB "> 9... 10 </ x s d : e l e m e n t> 11 </ xsd:schema> www.w3.org /001/ XMLSchema - instance "> <BBB xx="1">zzz</bbb> 3 </AAA> <x s d : e l e m e n t name=" AAA "> 3... 4 <x s d : e l e m e n t name=" BBB "> 5... 6 </ x s d : e l e m e n t> 7... 8 </ x s d : e l e m e n t> 9 </ xsd:schema> Dr inż. Stanisław Polak 9 Przedmiot: XML i jego zastosowania Dr inż. Stanisław Polak 10 Przedmiot: XML i jego zastosowania Definiowanie elementów i atrybutów Wymuszanie kwalifikowania elementów lub atrybutów Elementy typu prostego Definiowanie elementów i atrybutów Definiowanie elementu zawierającego tekst 1 <r o o t xsi:nonamespaceschemalocation=" correct_a. xsd " xmlns="" 3 x m l n s : x s i=" http: // www.w3.org /001/ XMLSchema - instance " >test 4 </ r o o t> 1 <root xsi: schemalocation=h t t p : // foo c o r r e c t 0. xsd xmlns=" http: // foo " x m l n s : x s i=" http: // www.w3.org /001/ XMLSchema - instance "> <e1 xmlns= >Element 1</ e1> 3 </ r o o t> www.w3.org /001/ XMLSchema - instance " >xxx yyy</aaa> 1 <x s d:schema elementformdefault=" qualified " attributeformdefault=" unqualified " x m l n s : x s d=" http: // www.w3.org /001/ XMLSchema "> <! Atrybutu " form " n i e moż na stosowa ć gdy bezpo ś rednim elementem r o d z i c i e l s k i m j e s t " schema " > 3 <x s d : e l e m e n t name=" root " t y p e=" xsd:string " form=" qualified "/> 4 </ x sd:schema> correct A.xsd 1 <xsd:schema targetnamespace=" http: // foo " elementformdefault= unqualified x m l n s : x s d=" http: // www.w3.org /001/ XMLSchema " x m l n s : f o o=" http: // foo "> 3 <x s d : e l e m e n t name=" root "> 4... 5 <x s d : e l e m e n t name="e1" t y p e=" xsd:string "/> 6... 7 </ x sd:schema> 1 <xsd:schema x m l n s : x s d=" http: // www.w3.org /001/ XMLSchema " > <x s d : e l e m e n t name="aaa " t y p e=" xsd:string "/> 3 </ xsd:schema> Dr inż. Stanisław Polak 11 Przedmiot: XML i jego zastosowania Dr inż. Stanisław Polak 1 Przedmiot: XML i jego zastosowania
Elementy typu złożonego Definiowanie elementów i atrybutów Definiowanie elementu pustego Elementy typu złożonego Definiowanie elementów i atrybutów Definiowanie elementu zawierającego zawartość mieszaną www.w3.org /001/ XMLSchema - instance " /> 4 <xsd:complextype> 5 <x s d : c o m p l e x C o n t e n t> 6 <x s d : r e s t r i c t i o n base=" xsd:anytype "/> 7 </ x s d :complexcontent> 8 </ xsd:complextype> 9 </ x s d : e l e m e n t> 10 </ xsd:schema> www.w3.org /001/ XMLSchema - instance " > xxx yyy <BBB>ZZZ</BBB> aaa 3 </AAA> 4 <xsd:complextype mixed= true > 5 <x s d : s e q u e n c e minoccurs="1"> 6 <x s d : e l e m e n t name="bbb " t y p e=" xsd:string "/> 7 </ x s d : s e q u e n c e> 8 </ xsd:complextype> 9 </ x s d : e l e m e n t> 10 </ xsd:schema> Dr inż. Stanisław Polak 13 Przedmiot: XML i jego zastosowania Dr inż. Stanisław Polak 14 Przedmiot: XML i jego zastosowania Elementy typu złożonego Definiowanie elementów i atrybutów Definiowanie elementu zawierającego elementy Dowolna kolejność ich wystąpień Elementy typu złożonego Definiowanie elementów i atrybutów Definiowanie elementu zawierającego elementy Ściśle określona kolejność ich wystąpień www.w3.org /001/ XMLSchema - instance "> <BBB>ZZZ</BBB> 3 <CCC>YYY</CCC> 4 </AAA> 4 <xsd:complextype mixed=" false "> 5 <x s d : all> 6 <x s d : e l e m e n t name="bbb " t y p e=" xsd:string "/> 7 <x s d : e l e m e n t name="ccc " t y p e=" xsd:string "/> 8 </ x s d : all> 9 </ xsd:complextype> 10 </ x s d : e l e m e n t> 11 </ xsd:schema> www.w3.org /001/ XMLSchema - instance "> <BBB>ZZZ</BBB> 3 <CCC>YYY</CCC> 4 <BBB>ZZZ</BBB> 5 <BBB>ZZZ</BBB> 6 <CCC>YYY</CCC> 7 </AAA> 4 <xsd:complextype mixed=" false "> 5 <xsd:sequence minoccurs="0" maxoccurs="unbounded"> 6 <x s d : e l e m e n t name="bbb " t y p e=" xsd:string " minoccurs= 0 /> 7 <x s d : e l e m e n t name="ccc " t y p e=" xsd:string " minoccurs= 0 /> 8 </ x s d : sequence> 9 </ xsd:complextype> 10 </ x s d : e l e m e n t> 11 </ xsd:schema> Dr inż. Stanisław Polak 15 Przedmiot: XML i jego zastosowania Dr inż. Stanisław Polak 16 Przedmiot: XML i jego zastosowania
Elementy typu złożonego Definiowanie elementów i atrybutów Definiowanie elementu zawierającego elementy Przeplatanie innymi elementami 1 <AAA xsi:nonamespaceschemalocation=" correct_0.xsd " xmlns="" x m l n s : f="... " x m l n s : x s i=" http: // www.w3.org /001/ XMLSchema - instance "> <f:zzz>bbb</ f:zzz> 3 <BBB>ZZZ</BBB> 4 <f:xxx>ccc</ f:xxx> 5 <CCC>YYY</CCC> 6 <f:yyy>aaa</ f:yyy> 7 </AAA> 4 <xsd:complextype> 5 <x s d : opencontent mode=" interleave "> 6 <x s d : a n y /> 7 </ x s d : opencontent> 8 <x s d : s e q u e n c e> 9 <x s d : e l e m e n t name="bbb " t y p e=" xsd:string " /> 10 <x s d : e l e m e n t name="ccc " t y p e=" xsd:string " /> 11 </ x s d : s e q u e n c e> 1 </ xsd:complextype> 13 </ x s d : e l e m e n t> 14 </ xsd:schema> Elementy typu złożonego Definiowanie elementów i atrybutów Definiowanie elementu zawierającego jeden z kilku elementów www.w3.org /001/ XMLSchema - instance " > <BBB>111</BBB> 3 </AAA> 4 <xsd:complextype mixed=" false "> 5 <x s d : choice> 6 <x s d : e l e m e n t name="bbb " t y p e=" xsd:string "/> 7 <x s d : e l e m e n t name="ccc " t y p e=" xsd:string "/> 8 </ x s d : choice> 9 </ xsd:complextype> 10 </ x s d : e l e m e n t> 11 </ xsd:schema> Dr inż. Stanisław Polak 17 Przedmiot: XML i jego zastosowania Dr inż. Stanisław Polak 18 Przedmiot: XML i jego zastosowania Elementy typu złożonego Definiowanie elementów i atrybutów Definiowanie elementu zawierającego tekst i posiadającego atrybut Elementy typu złożonego Definiowanie elementów i atrybutów Określanie alternatywnych typów elementu 1 <f:aaa x s i : s c h e m a L o c a t i o n=" http: // foo correct_0.xsd " xx="1" x m l n s : f=" http: // foo " x m l n s : x s i=" http: // www.w3.org /001/ XMLSchema - instance " >qwerty uiop</ f:aaa> 1 <xsd:schema targetnamespace=" http: // foo " x m l n s : x s d=" http: // www.w3.org /001/ XMLSchema " x m l n s : f o o=" http: // foo "> 4 <xsd:complextype> 5 <x s d : s i m p l e C o n t e n t> 6 <x s d : e x t e n s i o n base=" xsd:string "> 7 <x s d : a t t r i b u t e name="xx" t y p e=" xsd:string " use=" required "/> 8 </ x s d : e x t e n s i o n> 9 </ x s d : s i m p l e C o n t e n t> 10 </ xsd:complextype> 11 </ x s d : e l e m e n t> 1 </ xsd:schema> 1 <xsd:complextype name=" messagetypestring ">... 3 </ xsd:complextype> 4 5 <xsd:complextype name=" messagetypebase64 "> 6... 7 </ xsd:complextype> 8 9 <xsd:complextype name=" messagetypexml "> 10... 11 </ xsd:complextype> 1 13 <x s d : e l e m e n t name=" message " t y p e=" messagetype "> 14 <xsd: alternative t e s t=" @kind= string " type=" messagetypestring "/> 15 <xsd: alternative t e s t=" @kind= base64 " type=" messagetypebase64 "/> 16 <xsd: alternative t e s t=" @kind= binary " type=" messagetypebase64 "/> 17 <xsd: alternative t e s t=" @kind= xml " type=" messagetypexml "/> 18 <xsd: alternative t e s t=" @kind= XML " type=" messagetypexml "/> 19 <xsd: alternative t e s t=" @kind= book " type="xsd:error" /> 0 <x s d : alternative t y p e=" messagetype "/> 1 </ x s d : e l e m e n t> Dr inż. Stanisław Polak 19 Przedmiot: XML i jego zastosowania Dr inż. Stanisław Polak 0 Przedmiot: XML i jego zastosowania
Wbudowane typy danych Typy proste Własne typy proste Typy proste Tworzenie własnych typów Znakowy 1. string. normalizedstring 3. token 4.... Data i czas date time datetime duration... Liczbowe... Inne decimal integer int boolean base64binary hexbinary anyuri... 1 <! d a t e > 011 05 04 3 <! z uwzgl ę dnieniem przesuni ę c i a czasowego > 4 011 05 04+0:00 5 <! time > 6 09 :00:00 7 09 :00:00. 8 8 09 :00:00+0:00 9 <! datetime > 10 011 05 04T09:00:00 11 011 05 04T09:00:00. 8 1 011 05 04T09:00:00+0:00 13 <! d u r a t i o n > 14 P5YM10DT15H Przykłady simpletype restriction union list Sposoby tworzenia Zawężanie innego typu prostego Suma innych typów prostych Lista wartości innego typu prostego Dr inż. Stanisław Polak 1 Przedmiot: XML i jego zastosowania Dr inż. Stanisław Polak Przedmiot: XML i jego zastosowania Własne typy proste Typy proste Zawężanie typu prostego Własne typy proste Typy proste Suma typów prostych Aspekty maxexclusive minexclusive maxinclusive mininclusive enumeration pattern totaldigits fractiondigits length maxlength minlength whitespace assertion explicittimezone 1 <x s d : e l e m e n t name=" root "> <x s d : s i m p l e T y p e> 3 <x s d : r e s t r i c t i o n base=" xsd:integer "> 4 <x s d : m a x E x c l u s i v e v a l u e="5"/> 5 </ x s d : r e s t r i c t i o n> 6 </ x s d : s i m p l e T y p e> 7 </ x s d : e l e m e n t> Wartością elementu jest liczba < 5 1 <xsd:schema x m l n s : x s d=" http: // www.w3.org /001/ XMLSchema " > 3 <x s d : s i m p l e T y p e> 4 <x s d : union> 5 <x s d : s i m p l e T y p e> 6 <x s d : r e s t r i c t i o n base=" xsd:integer "> 7 <x s d : m i n I n c l u s i v e v a l u e="0"/> 8 <x s d : m a x I n c l u s i v e v a l u e=" 100 "/> 9 </ x s d : r e s t r i c t i o n> 10 </ x s d : s i m p l e T y p e> 11 <x s d : s i m p l e T y p e> 1 <x s d : r e s t r i c t i o n base=" xsd:integer "> 13 <x s d : m i n I n c l u s i v e v a l u e=" 300 "/> 14 <x s d : m a x I n c l u s i v e v a l u e=" 400 "/> 15 </ x s d : r e s t r i c t i o n> 16 </ x s d : s i m p l e T y p e> 17 </ x s d : union> 18 </ x s d : s i m p l e T y p e> 19 </ x s d : e l e m e n t> 0 </ xsd:schema> Wartość elementu [0... 100, 300... 400] Dr inż. Stanisław Polak 3 Przedmiot: XML i jego zastosowania Dr inż. Stanisław Polak 4 Przedmiot: XML i jego zastosowania
Własne typy proste Typy proste Lista wartości typu prostego Typy nazwane Typy proste Definiowanie typu nazwanego Pusta przestrzeń nazw 1 <r o o t xsi:nonamespaceschemalocation=" correct_0.xsd " xyz="0 0 1" xmlns="" x m l n s : x s i=" http: // www.w3.org /001/ XMLSchema - instance "/> 1 <xsd:schema x m l n s : x s d=" http: // www.w3.org /001/ XMLSchema " > 4 <x s d : a t t r i b u t e name=" xyz " use=" required "> 5 <x s d : s i m p l e T y p e> 6 <x s d : r e s t r i c t i o n base=" mylist "> 7 <x s d : l e n g t h v a l u e="3"/> 8 </ x s d : r e s t r i c t i o n> 9 </ x s d : s i m p l e T y p e> 10 </ x s d : a t t r i b u t e> 11 </ xsd:complextype> 1 </ x s d : e l e m e n t> 13 14 <x s d : s i m p l e T y p e name=" mylist "> 15 <x s d : list itemtype=" xsd:integer "/> 16 </ x s d : s i m p l e T y p e> 17 </ xsd:schema> 1 <T xsi:nonamespaceschemalocation=" correct_0.xsd " xmlns="" x m l n s : x s i=" http: // www. w3.org /001/ XMLSchema - instance " > 10 </T> 1 <xsd:schema x m l n s : x s d=" http: // www.w3.org /001/ XMLSchema " > 3 <x s d : e l e m e n t name="t" t y p e= "Temperatura" /> 4 5 <x s d : s i m p l e T y p e name= "Temperatura" > 6 <x s d : r e s t r i c t i o n base=" xsd:double "> 7 <x s d : m i n E x c l u s i v e v a l u e=" -73.15 "/> 8 </ x s d : r e s t r i c t i o n> 9 </ x s d : s i m p l e T y p e> 10 </ x sd:schema> Dr inż. Stanisław Polak 5 Przedmiot: XML i jego zastosowania Dr inż. Stanisław Polak 6 Przedmiot: XML i jego zastosowania Typy nazwane Typy proste Definiowanie typu nazwanego Określona przestrzeń nazw Grupy Definiowanie grupy elementów 1 <root xsi: schemalocation=" http: // foo correct_0.xsd " xmlns=" http: // foo " x m l n s : x s i =" http: // www.w3.org /001/ XMLSchema - instance " >4</ r o o t> 1 <xsd:schema targetnamespace=" http: // foo " x m l n s : x s d=" http: // www.w3.org /001/ XMLSchema " x m l n s : f o o=" http: // foo "> 3 <x s d : e l e m e n t name=" root " t y p e="foo:myinteger"/> 4 5 <x s d : s i m p l e T y p e name="myinteger"> 6 <x s d : r e s t r i c t i o n base=" xsd:integer "/> 7 </ x s d : s i m p l e T y p e> 8 </ x sd:schema> 1 <x s : g r o u p name=" custgroup "> <x s : s e q u e n c e> 3 <x s : e l e m e n t name=" customer " t y p e=" xs:string "/> 4 <x s : e l e m e n t name=" orderdetails " t y p e=" xs:string "/> 5 <x s : e l e m e n t name=" billto " t y p e=" xs:string "/> 6 <x s : e l e m e n t name=" shipto " t y p e=" xs:string "/> 7 </ x s : s e q u e n c e> 8 </ x s : g r o u p> 9 10 <x s : e l e m e n t name=" order " t y p e=" ordertype "/> 11 1 <x s:complextype name=" ordertype "> 13 <xs: group r e f=" custgroup "/> 14 <x s : a t t r i b u t e name=" status " t y p e=" xs:string "/> 15 </ xs:complextype> Dr inż. Stanisław Polak 7 Przedmiot: XML i jego zastosowania Dr inż. Stanisław Polak 8 Przedmiot: XML i jego zastosowania
Grupy Symbole wieloznaczne Definiowanie grupy atrybutów Symbole wieloznaczne 1 <r o o t xsi:nonamespaceschemalocation=" correct_0. xsd " xmlns="" x m l n s : x s i=" http: // www.w3.org /001/ XMLSchema -instance " > <aaa x="1" y=""/> 3 <bbb x="3" y="4"/> 4 </ r o o t> 1 <xsd:schema x m l n s : x s d="http: //www.w3.org /001/ XMLSchema " defaultattributes="myattrs "> 4 <x s d : s e q u e n c e> 5 <x s d : e l e m e n t name=" aaa " minoccurs="1" maxoccurs="1"> 6 <xsd:complextype> 7 <x s d : attributegroup r e f=" myattrs "/> 8 </ xsd:complextype> 9 </ x s d :element> 10 <x s d : e l e m e n t name=" bbb " minoccurs="1" maxoccurs="1"> 11 <xsd:complextype> 1 <x s d : attributegroup r e f=" myattrs "/> 13 </ xsd:complextype> 14 </ x s d :element> 15 </ x s d :sequence> 16 </ xsd:complextype> 17 </ x s d :element> 18 19 <x s d : a t t r i b u t e G r o u p name=" myattrs "> 0 <x s d : a t t r i b u t e name="x" t y p e=" xsd:integer " use=" required "/> 1 <x s d : a t t r i b u t e name="y" t y p e=" xsd:integer " use=" required "/> </ x s d :attributegroup> 3 </ x sd:schema> 1 <any i d = ID 3 maxoccurs = ( nonnegativeinteger unbounded ) : 1 4 minoccurs = n o n N e g a t i v e I n t e g e r : 1 5 namespace = "(##any ##other) List of ( anyuri (##targetnamespace ##local))) : ## any 6 notnamespace = List of ( anyuri (## targetnamespace ## local )) 7 notqname = List of ( QName (## defined ## definedsibling )) 8 processcontents = (strict lax skip) : strict 9 {any attributes with non - schema Namespace...} > 10 Content: ( annotation?) 11 </any> Symbol ogólny elementu 1 <anyattribute i d = ID 3 namespace = "(##any ##other) List of ( anyuri (##targetnamespace ##local))) : ## any 4 notnamespace = List of ( anyuri (## targetnamespace ## local )) 5 notqname = List of ( QName ## defined ) 6 processcontents = (strict lax skip) : strict 7 {any attributes with non - schema Namespace...} > 8 Content: ( annotation?) 9 </anyattribute> Symbol ogólny atrybutu Dr inż. Stanisław Polak 9 Przedmiot: XML i jego zastosowania Dr inż. Stanisław Polak 30 Przedmiot: XML i jego zastosowania Symbole wieloznaczne Symbole wieloznaczne Przykład Użycie <anyattribute> Przykład Użycie <anyattribute> oraz ##other 1 <root xsi:nonamespaceschemalocation=" correct_0.xsd " xmlns="" x m l n s : x s i=" http: // www.w3.org /001/ XMLSchema - instance " x m l n s : b a z=" http: // baz " x="" 3 b a z : x="" /> 1 <xsd:schema x m l n s : x s d=" http: // www.w3.org /001/ XMLSchema " > 4 <x s d : anyattribute namespace="##any" p r o c e s s C o n t e n t s=" skip "/> 5 </ xsd:complextype> 6 </ x s d : e l e m e n t> 7 </ xsd:schema> 1 <f o o : r o o t xsi: schemalocation=" http: // foo correct_0.xsd " xmlns: foo=" http: // foo " x m l n s : x s i=" http: // www.w3.org /001/ XMLSchema - instance " f o o : a="1" /> 1 <xsd:schema targetnamespace=" http: // foo " x m l n s : x s d=" http: // www.w3.org /001/ XMLSchema " > 4 <x s d : anyattribute namespace="##other" p r o c e s s C o n t e n t s=" skip "/> 5 </ xsd:complextype> 6 </ x s d : e l e m e n t> 7 </ xsd:schema> Dr inż. Stanisław Polak 31 Przedmiot: XML i jego zastosowania Dr inż. Stanisław Polak 3 Przedmiot: XML i jego zastosowania
Symbole wieloznaczne Symbole wieloznaczne Przykład Użycie <any>, minoccurs, maxoccurs oraz ##any Przykład Użycie <any> oraz ##other 1 <root xsi:nonamespaceschemalocation=" correct_0.xsd " xmlns="" x m l n s : x s i=" http: // www.w3.org /001/ XMLSchema - instance " > <x : b x m l n s : x=" http: // foo " /> 3 </ r o o t> 1 <root xsi:nonamespaceschemalocation=" correct_0.xsd " xmlns="" x m l n s : x s i=" http: // www.w3.org /001/ XMLSchema - instance " > <a/> 3 </ r o o t> 1 <xsd:schema x m l n s : x s d=" http: // www.w3.org /001/ XMLSchema " > 4 <x s d : s e q u e n c e> 5 <x s d : any namespace="##any" minoccurs="1" maxoccurs="1" p r o c e s s C o n t e n t s=" skip "/> 6 </ x s d : s e q u e n c e> 7 </ xsd:complextype> 8 </ x s d : e l e m e n t> 9 </ xsd:schema> 1 <xsd:schema x m l n s : x s d=" http: // www.w3.org /001/ XMLSchema " > 4 <x s d : s e q u e n c e> 5 <x s d : any namespace="##other" minoccurs="0" maxoccurs=" unbounded " p r o c e s s C o n t e n t s=" skip "/> 6 </ x s d : s e q u e n c e> 7 </ xsd:complextype> 8 </ x s d : e l e m e n t> 9 </ xsd:schema> Dr inż. Stanisław Polak 33 Przedmiot: XML i jego zastosowania Dr inż. Stanisław Polak 34 Przedmiot: XML i jego zastosowania Zewnętrzne Schematy Zewnętrzne Schematy Import definicji z innych przestrzeni nazw 1 <f o o : r o o t x s i :schemalocation=" http: // foo correct_0. xsd " x m l n s :foo=" http: // foo " x m l n s : x s i=" http: //www.w3.org /001/ XMLSchema -instance " x m l n s : b a r="http: //bar " > <bar:x>1</bar:x> 3 <bar:x></bar:x> 4 <x xmlns="">3</x> 5 <bar:x>aaaa</bar:x> 6 </ f o o : r o o t> 1 <xsd:schema targetnamespace="http: //foo " x m l n s : x s d="http: //www.w3.org /001/ XMLSchema " > <x s d : i m p o r t namespace=" http: // bar " schemalocation=" correct_1. xsd "/> 3 <x s d : e l e m e n t name=" root "> 4 <xsd:complextype> 5 <x s d : s e q u e n c e minoccurs="1" maxoccurs="1"> 6 <x s d : a n y namespace="## other " minoccurs="0" maxoccurs=" unbounded " p r o c e s s C o n t e n t s="lax"/> 7 </ x s d :sequence> 8 </ xsd:complextype> 9 </ x s d :element> 10 </ x sd:schema> Tworzenie Schematu z wielu plików Użycie <include> 1 <? xml version=" 1.0 "?> <x s : s c h e m a e l e m e n t F o r m D e f a u l t=" qualified " targetnamespace=" http: // www.w3.org /001/05/ XMLInfoset " xmlns=" http: // www.w3.org /001/ XMLSchema "> 3 <x s : i m p o r t namespace=" http: // www. przyklad.pl/" /> 4 <x s : i n c l u d e schemalocation=" przyklad. xsd " /> 5 </ x s :schema> 1 <xsd:schema targetnamespace="http: //bar " x m l n s : x s d="http: //www.w3.org /001/ XMLSchema " > <x s d : e l e m e n t name="x" t y p e=" xsd:integer "/> 3 </ x sd:schema> correct 1.xsd Dr inż. Stanisław Polak 35 Przedmiot: XML i jego zastosowania Dr inż. Stanisław Polak 36 Przedmiot: XML i jego zastosowania
Zewnętrzne Schematy Tworzenie Schematu z wielu plików Użycie <override> Uchylanie definicji Atrybuty xsi:nil oraz nillable 1 <f o o : r o o t x s i :schemalocation=" http: // foo correct_1. xsd " x m l n s :foo=" http: // foo " x m l n s : x s i=" http: //www.w3.org /001/ XMLSchema -instance " x m l n s :bar="http: //bar "bas>abcde</ f o o : r o o t> 1 <xsd:schema targetnamespace="http: //foo " x m l n s : x s d="http: //www.w3.org /001/ XMLSchema " x m l n s : f o o= " http: // foo " > <x s d : override schemalocation=" correct_0. xsd "> 3 <x s d : s i m p l e T y p e name=" mystring "> 4 <x s d : r e s t r i c t i o n base=" foo:mystring "> 5 <xsd:maxlength v a l u e="5"/> 6 </ x s d : r e s t r i c t i o n> 7 </ x s d :simpletype> 8 </ x s d :override> 9 </ x sd:schema> correct 1.xsd 1 <xsd:schema targetnamespace="http: //foo " x m l n s : x s d="http: //www.w3.org /001/ XMLSchema " x m l n s : f o o= " http: // foo " > <x s d : e l e m e n t name=" root " t y p e=" foo:mystring "/> 3 <x s d : s i m p l e T y p e name=" mystring "> 4 <x s d : r e s t r i c t i o n base=" xsd:string "/> 5 </ x s d :simpletype> 6 </ x sd:schema> 1 <r o o t xsi:nonamespaceschemalocation=" correct_0.xsd " xsi:nil="true" xmlns="" x m l n s : x s i=" http: // www.w3.org /001/ XMLSchema - instance " > <e1>xxx</ e1> 3 </ r o o t> 1 <xsd:schema x m l n s : x s d=" http: // www.w3.org /001/ XMLSchema " > <x s d : e l e m e n t name=" root " nillable=" true "> 4 <x s d : s e q u e n c e> 5 <x s d : e l e m e n t name="e1" t y p e=" xsd:string "/> 6 </ x s d : s e q u e n c e> 7 </ xsd:complextype> 8 </ x s d : e l e m e n t> 9 </ xsd:schema> Dr inż. Stanisław Polak 37 Przedmiot: XML i jego zastosowania Dr inż. Stanisław Polak 38 Przedmiot: XML i jego zastosowania Zmienianie typu elementu Atrybut xsi:type Ograniczenia unikalności Użycie <unique> lub <key> 1 <root xsi:nonamespaceschemalocation=" correct_0.xsd " xmlns="" x m l n s : x s i=" http: // www.w3.org /001/ XMLSchema - instance " x m l n s : x s d=" http: // www.w3.org /001/ XMLSchema "> <e xsi:type="myinteger">10</ e> 3 </ r o o t> 1 <root xsi:nonamespaceschemalocation=" correct_0.xsd " xmlns="" x m l n s : x s i=" http: // www.w3.org /001/ XMLSchema - instance "> <a/> 3 <a i d="y"/> 4 <a i d="z"/> 5 </ r o o t> 4 <x s d : s e q u e n c e> 5 <x s d : e l e m e n t name="e" t y p e=" xsd:decimal "/> 6 </ x s d : s e q u e n c e> 7 </ xsd:complextype> 8 </ x s d : e l e m e n t> 9 10 <x s d : s i m p l e T y p e name="myinteger"> 11 <x s d : r e s t r i c t i o n base=" xsd:integer "/> 1 </ x s d : s i m p l e T y p e> 13 14 <x s d : s i m p l e T y p e name="myfloat"> 15 <x s d : r e s t r i c t i o n base=" xsd:float "/> 16 </ x s d : s i m p l e T y p e> 17 </ xsd:schema> <x s d : e l e m e n t name="root " t y p e=" mylist "> 3 <x s d : unique name=" myid "> 4 <x s d : selector xpath="./a"/> 5 <x s d : field xpath=" @id "/> 6 </ x s d : unique> 7 </ x s d : e l e m e n t> 8 <xsd:complextype name=" mylist "> 9 <x s d : s e q u e n c e minoccurs="1"> 10 <x s d : e l e m e n t name="a" minoccurs="1" maxoccurs=" unbounded "> 11 <xsd:complextype> 1 <x s d : a t t r i b u t e name="id" t y p e=" xsd:ncname "/> 13 </ xsd:complextype> 14 </ x s d : e l e m e n t> 15 </ x s d : s e q u e n c e> 16 </ xsd:complextype> 17 </ xsd:schema> Dr inż. Stanisław Polak 39 Przedmiot: XML i jego zastosowania Dr inż. Stanisław Polak 40 Przedmiot: XML i jego zastosowania
Integralność referencyjna Użycie <keyref> Kontrolowanie tworzenia i używania typów pochodnych 1 <r o o t xsi:nonamespaceschemalocation=" correct_0. xsd " xmlns="" x m l n s : x s i=" http: // www.w3. org /001/ XMLSchema -instance "> <AAA> 3 <a i d="x"/> 4 <a i d="y"/> 5 </AAA> 6 <BBB> 7 <b i d r e f="x"/> 8 <b i d r e f="y"/> 9 <b i d r e f="y"/> 10 </BBB> 11 </ r o o t> 1 <xsd:schema x m l n s : x s d=" http: // www.w3.org /001/ XMLSchema "> 4 <x s d : s e q u e n c e minoccurs="1" maxoccurs="1"> 5 <x s d : e l e m e n t name=" AAA " t y p e=" myaaa "/> 6 <x s d : e l e m e n t name=" BBB " t y p e=" mybbb "/> 7 </ x s d :sequence> 8 </ xsd:complextype> 9 10 <x s d : k e y name=" myid "> 11 <x s d : s e l e c t o r xpath="./ AAA /a"/> 1 <x s d : f i e l d xpath=" @id "/> 13 </ x s d :key> 14 15 <x s d : keyref name=" myidref " r e f e r=" myid "> 16 <x s d : s e l e c t o r xpath="./ BBB /b"/> 17 <x s d : f i e l d xpath=" @idref "/> 18 </ x s d :keyref> 19 </ x s d :element> 0... 1 </ x sd:schema> 1 <xsd:schema finaldefault= #all x m l n s : x s d=" http: // www.w3.org /001/ XMLSchema " > <x s d : e l e m e n t name=" root " t y p e=" AAA "/> 3 4 <! f i n a l=" restriction extension union list #all " > 5 <x s d : s i m p l e T y p e name="aaa " final=" restriction "> 6 <x s d : r e s t r i c t i o n base=" xsd:integer "> 7 <x s d : m i n I n c l u s i v e v a l u e="0"/> 8 </ x s d : r e s t r i c t i o n> 9 </ x s d : s i m p l e T y p e> 10 11 <x s d : s i m p l e T y p e name=" BBB "> 1 <x s d : r e s t r i c t i o n base=" AAA "> 13 <x s d : m i n I n c l u s i v e v a l u e="10"/> 14 </ x s d : r e s t r i c t i o n> 15 </ x s d : s i m p l e T y p e> 16 </ xsd:schema> Dr inż. Stanisław Polak 41 Przedmiot: XML i jego zastosowania Dr inż. Stanisław Polak 4 Przedmiot: XML i jego zastosowania Elementy abstrakcyjne, grupy substytucji 1 <xsd:schema x m l n s : x s d="http: //www.w3.org /001/ XMLSchema " blockdefault= #all > 4 <x s d : s e q u e n c e minoccurs="1"> 5 <x s d : e l e m e n t r e f=" myabstract "/> 6 </ x s d :sequence> 7 </ xsd:complextype> 8 </ x s d :element> 9 10 <! b l o c k="substitution restriction extension #all " > 11 <x s d : e l e m e n t name= myabstract t y p e=" AAA " abstract= true block= substitution /> 1 <x s d : s i m p l e T y p e name=" AAA "> 13... 14 </ x s d :simpletype> 15 16 <x s d : e l e m e n t name=" odd " substitutiongroup= myabstract > 17 <x s d : s i m p l e T y p e> 18 <x s d : r e s t r i c t i o n base=" AAA "> 19... 0 </ x s d : r e s t r i c t i o n> 1 </ x s d :simpletype> </ x s d :element> 3 </ x sd:schema> 1 <r o o t> <! uż yto elementu abstrakcyjnego > 3 <myabstract>7</ myabstract> 4 </ r o o t> Niepoprawny dokument XML 1 <r o o t> <odd>7</odd> 3 </ r o o t> Poprawny dokument XML Asercje Element assert 1 <xsd:complextype name=" zakres "> <x s d : a t t r i b u t e name=" min " t y p e=" xsd:int "/> 3 <x s d : a t t r i b u t e name=" max " t y p e=" xsd:int "/> 4 <xsd: assert t e s t=" @min le @max "/> 5 </ xsd:complextype> Wartość atrybutu min max 1 <x s d : e l e m e n t name=" book "> <xsd:complextype> 3 <x s d : s e q u e n c e> 4 <x s d : e l e m e n t name=" title " t y p e=" xsd:string " /> 5 <x s d : e l e m e n t name=" author " t y p e=" xsd:string " /> 6 <x s d : e l e m e n t name=" publisher " t y p e=" xsd:string " /> 7 </ x s d : s e q u e n c e> 8 <xsd: assert t e s t="( publisher eq Springer ) or ( publisher eq WNT )" /> 9 </ xsd:complextype> 10 </ x s d : e l e m e n t> Wydawca musi być łańcuchem Springer lub WNT Dr inż. Stanisław Polak 43 Przedmiot: XML i jego zastosowania Dr inż. Stanisław Polak 44 Przedmiot: XML i jego zastosowania
Atrybut dziedziczony Adnotacje 1 <e l e m e n t name=" BookStore "> <complextype> 3 <s e q u e n c e> 4 <e l e m e n t name="book " maxoccurs=" unbounded "> 5 <complextype> 6 <s e q u e n c e> 7 <e l e m e n t name=" Title " t y p e=" string " /> 8 <e l e m e n t name=" Author " t y p e=" string " /> 9 <e l e m e n t name="date " t y p e=" string " /> 10 <e l e m e n t name="isbn " t y p e=" string " /> 11 <e l e m e n t name=" Publisher " t y p e=" string " /> 1 </ s e q u e n c e> 13 <a s s e r t t e s t="if ( @xml:lang = en ) then 14 ( Publisher eq Wrox Press ) or 15 ( Publisher eq McMillan Publishing ) 16 else if ( @xml:lang = fr then 17 ( Publisher eq Bayard Presse ) or 18 ( Publisher eq Le Castor Astral ) 19 else false ()" /> 0 </ complextype> 1 </ e l e m e n t> </ s e q u e n c e> 3 <a t t r i b u t e r e f=" xml:lang " inheritable=" true " /> 4 </ complextype> 5 </ e l e m e n t> 1 <xsd:schema x m l n s : x s d=" http: // www.w3.org /001/ XMLSchema " > <x s d : annotation> 3 <x s d : documentation> 4 Mój element "root ", który zawiera tylko ł ańcuch znak ów 5 </ x s d : documentation> 6 <x s d : appinfo> 7 <! tu i n f o r m a c j e d l a n a r z ę d z i, a r k u s z y s t y l ów, i n n y c h a p l i k a c j i, i t p. > 8 </ x s d : appinfo> 9 </ x s d : annotation> 10 <x s d : e l e m e n t name="root " t y p e=" xsd:string "/> 11 </ xsd:schema> Dr inż. Stanisław Polak 45 Przedmiot: XML i jego zastosowania Dr inż. Stanisław Polak 46 Przedmiot: XML i jego zastosowania Kontrola wersji Rozpoznawanie wersji języka wspieranej przez walidator Kontrola wersji Sprawdzanie obsługi własnych typów danych dostawców 1 <schema... x m l n s : vc= http://www.w3.org/007/xmlschema-versioning"> 3 < element name =" book " vc:minversion=" 3. "> 4 <!-- deklaracja elementu book --> 5 <!-- nr wersji ję zyka 3. --> 6 </ element > 7 < element name =" book " vc:minversion =" 1. 1 " vc:maxversion=" 3. "> 8 <!-- deklaracja elementu book --> 9 <!-- 1.1 nr wersji ję zyka < 3. --> 10 </ element > 11 1 </ schema > 1 <e l e m e n t name="cena " v c : typeavailable=" vendor:decimal " t y p e="vendor:decimal" /> <e l e m e n t name="cena " v c : typeunavailable=" vendor:decimal " t y p e=" decimal " /> Dr inż. Stanisław Polak 47 Przedmiot: XML i jego zastosowania Dr inż. Stanisław Polak 48 Przedmiot: XML i jego zastosowania
Kontrola wersji Źródła Sprawdzanie obsługi własnych aspektów dostawców Źródła 1 <e l e m e n t name=" population " vc:facetavailable=" vendor:delimiter "> <simpletype> 3 <r e s t r i c t i o n base=" integer "> 4 <vendor:delimiter t e s t="," /> 5 </ r e s t r i c t i o n> 6 </ simpletype> 7 </ e l e m e n t> 8 <e l e m e n t name=" population " v c : facetunavailable=" vendor:delimiter " t y p e=" integer " /> Roger L. Costello. XML Schema 1.1 Tutorial. http://www.xfront.com/xml-schema-1-1/. W3C. XML Schema Part : Datatypes Second Edition. http://www.w3.org/tr/xmlschema-/. W3schools. XPath Tutorial. http://www.w3schools.com/xpath/default.asp. Zvon. XML Schema 001 and Relax NG Tutorial. http://zvon.org/xxl/xmlschematutorial/output/. Dr inż. Stanisław Polak 49 Przedmiot: XML i jego zastosowania Dr inż. Stanisław Polak 50 Przedmiot: XML i jego zastosowania