Date post: | 06-Mar-2016 |
Category: |
Documents |
Upload: | surendrapdaceg |
View: | 1 times |
Download: | 0 times |
7/21/2019 XML for Beginners
http://slidepdf.com/reader/full/xml-for-beginners-56dbd85348518 1/55
XML for BeginnersRalf Schenkel
1. XML – the Snake Oil of the Internet age?
2. Basic XML Concepts
3. Defining XML Data or!ats
". #$er%ing XML Data
7/21/2019 XML for Beginners
http://slidepdf.com/reader/full/xml-for-beginners-56dbd85348518 2/55
Snake Oil?
Snake Oil i! the all"c#ring dr#g the!e !trange g#$! in
wild"we!t mo%ie! !ell, tra%elling from town to town, &#t%i!iting each town onl$ once'
(oogle) *!na+e oil -ml⇒ !ome 2000 hit!
*XML re%ol#tionize! !oftware de%elopment *XML i! the all"healing, world"peace ind#cing tool for
comp#ter proce!!ing
*XML ena&le! application porta&ilit$
*.orget the /e&, XML i! the new wa$ to &#!ine!! *XML i! the c#re for $o#r data e-change, information
integration, data e-change, -"2"$, $o# name it pro&lem!
*XML, the Mother of all /e& Application na&ler!
*XML ha! &een the &e!t in%ention !ince !liced &read
7/21/2019 XML for Beginners
http://slidepdf.com/reader/full/xml-for-beginners-56dbd85348518 3/55
XML is not…
A replacement for HTML
&#t 45ML can &e generated from XML6 A presentation format
&#t XML can &e con%erted into one6
A programming language&#t it can &e #!ed with almo!t an$ lang#age6
A network transfer protocol
&#t XML ma$ &e tran!ferred o%er a networ+6
A database
&#t XML ma$ &e !tored into a data&a!e6
7/21/2019 XML for Beginners
http://slidepdf.com/reader/full/xml-for-beginners-56dbd85348518 4/55
But then – what is it?
XML is a meta markup languagefor text documents / textual data
XML allows to define languages
(„applications“ to represent textdocuments / textual data
7/21/2019 XML for Beginners
http://slidepdf.com/reader/full/xml-for-beginners-56dbd85348518 5/55
XML by Exa!le
<article>
<author>Gerhard Weikum</author>
<title>The Web in 10 Years</title>
</article>
a!$ to #nder!tand for h#man #!er!
er$ e-pre!!i%e !emantic! along with the data6
/ell !tr#ct#red, ea!$ to read and write from program!
5hi! loo+! nice, &#t:
7/21/2019 XML for Beginners
http://slidepdf.com/reader/full/xml-for-beginners-56dbd85348518 6/55
XML by Exa!le
<t108> <x87>Gerhard Weikum</x87>
<g10>The Web in 10 Years</g10>
</t108>
4ard to #nder!tand for h#man #!er!
<ot e-pre!!i%e no !emantic! along with the data6
/ell !tr#ct#red, ea!$ to read and write from program!
: thi! i! XML, too)
7/21/2019 XML for Beginners
http://slidepdf.com/reader/full/xml-for-beginners-56dbd85348518 7/55
XML by Exa!le
<data> ch37hgks73!"m#$d%3h"mgkds8d$8&lgnsmcns$83
</data>
Impo!!i&le to #nder!tand for h#man #!er! <ot e-pre!!i%e no !emantic! along with the data6
>n!tr#ct#red, read and write onl$ with !pecial program!
: and what a&o#t thi! XML doc#ment)
5he act#al &enefit of #!ing XML highl$ depend!
on the de!ign of the application'
7/21/2019 XML for Beginners
http://slidepdf.com/reader/full/xml-for-beginners-56dbd85348518 8/55
"ossible #$%antages of &sing XML
5r#l$ @orta&le ata
a!il$ reada&le &$ h#man #!er!
er$ e-pre!!i%e !emantic! near data6
er$ fle-i&le and c#!tomiza&le no finite tag !et6
a!$ to #!e from program! li&! a%aila&le6
a!$ to con%ert into other repre!entation!
XML tran!formation lang#age!6 Man$ additional !tandard! and tool!
/idel$ #!ed and !#pported
7/21/2019 XML for Beginners
http://slidepdf.com/reader/full/xml-for-beginners-56dbd85348518 9/55
#!!' Scenario () *ontent Mgt'
ata&a!e with
XML doc#ment!
Blient!
Bon%erter!XML245ML XML2/ML XML2@.
7/21/2019 XML for Beginners
http://slidepdf.com/reader/full/xml-for-beginners-56dbd85348518 10/55
#!!' Scenario +) ,ata Exchange
Legac$
S$!tem
e'g', SA@
CD26
Legac$
S$!tem
e'g',
Bo&ol6
XML
Adapter XML
Adapter
XML
EMBat, e&XML, Co!etta<et, Eiz5al+, :6
SE#$er
Order
7/21/2019 XML for Beginners
http://slidepdf.com/reader/full/xml-for-beginners-56dbd85348518 11/55
#!!' Scenario -) XML for Meta$ata <rd'()*
<rd')escri+tion rd'about,-htt+'//...dbs/ch03+d->
<dc'title>2 *rame.ork or</dc'title> <dc'creator>(al chenkel</dc'creator>
<dc'descri+tion>While there are</dc'descri+tion>
<dc'+ublisher>aarland 4ni#ersit5</dc'+ublisher>
<dc'sub!ect>6 9ndexing</dc'sub!ect>
<dc'rights>:o+5right </dc'rights> <dc't5+e>;lectronic )ocument</dc't5+e>
<dc'ormat>text/+d</dc'ormat>
<dc'language>en</dc'language>
</rd')escri+tion>
</rd'()*>
7/21/2019 XML for Beginners
http://slidepdf.com/reader/full/xml-for-beginners-56dbd85348518 12/55
#!!' Scenario .) ,ocuent Marku! <article>
<section id,1= title,9ntro=>
This article is about <index>6</index>
</section>
<section id,= title,ain (esults=>
<name>Weikum</name> <cite idre,Weik01=/> sho.s
the ollo.ing theorem ?see ection <re idre,1=/>@ <theorem id,theo'1= source,Weik01=>
*or an5 6 document xA
</theorem>
</section> <literature>
<cite id,Weik01=><author>Weikum</author></cite>
</literature>
</article>
7/21/2019 XML for Beginners
http://slidepdf.com/reader/full/xml-for-beginners-56dbd85348518 13/55
#!!' Scenario .) ,ocuent Marku!
oc#ment Mar+#p add! !tr#ct#ral and !emantic
information to doc#ment!, e'g' F Section!, S#&!ection!, 5heorem!, :
F Bro!! Ceference!
F Literat#re Bitation!
F Inde- ntrie!
F <amed ntitie!
5hi! allow! G#erie! li+e
F /hich article! cite /ei+#mH! XML paper from 2001 F /hich article! tal+ a&o#t the named entit$6 */ei+#m
7/21/2019 XML for Beginners
http://slidepdf.com/reader/full/xml-for-beginners-56dbd85348518 14/55
XML for Beginners
"art + – Basic XML *once!ts
2.1 XML Stan&ar&s '% the (3C
2.2 XML Doc$!ents2.3 )a!espaces
7/21/2019 XML for Beginners
http://slidepdf.com/reader/full/xml-for-beginners-56dbd85348518 15/55
+'( XML Stan$ar$s – an O%er%iew XML Bore /or+ing (ro#p)
F XML 1'0 .e& 199?6, 1'1 candidate for recommendation6
F XML <ame!pace! Jan 19996
F XML Incl#!ion candidate for recommendation6
XSL5 /or+ing (ro#p)
F XSL 5ran!formation! 1'0 <o% 19996, 2'0 planned
F X@ath 1'0 <o% 19996, 2'0 planned
F eXten!i&le St$le!heet Lang#age XSL".O6 1'0 Oct 20016
XML Lin+ing /or+ing (ro#p)
F XLin+ 1'0 J#n 20016
F X@ointer 1'0 March 2003, 3 !#&!tandard!6
XK#er$ 1'0 <o% 20026 pl#! man$ !#&!tandard!
XMLSchema 1'0 Ma$ 20016
:
7/21/2019 XML for Beginners
http://slidepdf.com/reader/full/xml-for-beginners-56dbd85348518 16/55
+'+ XML ,ocuents
/hatH! in an XML doc#ment
lement! Attri&#te!
pl#! !ome other detail!
!ee the Lect#re if $o# want to +now thi!6
7/21/2019 XML for Beginners
http://slidepdf.com/reader/full/xml-for-beginners-56dbd85348518 17/55
# Si!le XML ,ocuent
<article>
<author>Gerhard Weikum</author> <title>The Web in Ten Years</title>
<text>
<abstract>9n order to e#ol#e</abstract>
<section number,=1B title,=9ntroductionB>
The <index>Web</index> +ro#ides the uni#ersal
</section>
</text>
</article>
7/21/2019 XML for Beginners
http://slidepdf.com/reader/full/xml-for-beginners-56dbd85348518 18/55
# Si!le XML ,ocuent
<article>
<author>Gerhard Weikum</author> <title>The Web in Ten Years</title>
<text>
<abstract>9n order to e#ol#e</abstract>
<section number,=1B title,=9ntroductionB>
The <index>Web</index> +ro#ides the uni#ersal
</section>
</text>
</article>
!reel" definable tags
7/21/2019 XML for Beginners
http://slidepdf.com/reader/full/xml-for-beginners-56dbd85348518 19/55
#lement
$ontent of
t%e #lement
(&ubelements
and/or Text
# Si!le XML ,ocuent
<article>
<author>Gerhard Weikum</author> <title>The Web in Ten Years</title>
<text>
<abstract>9n order to e#ol#e</abstract>
<section number,=1B title,=9ntroductionB>
The <index>Web</index> +ro#ides the uni#ersal
</section>
</text>
</article>
#nd Tag
&tart Tag
7/21/2019 XML for Beginners
http://slidepdf.com/reader/full/xml-for-beginners-56dbd85348518 20/55
# Si!le XML ,ocuent
<article>
<author>Gerhard Weikum</author> <title>The Web in Ten Years</title>
<text>
<abstract>9n order to e#ol#e</abstract>
<section number,=1B title,=9ntroductionB>
The <index>Web</index> +ro#ides the uni#ersal
</section>
</text>
</article>
Attributes withname and 'alue
7/21/2019 XML for Beginners
http://slidepdf.com/reader/full/xml-for-beginners-56dbd85348518 21/55
Eleents in XML ,ocuents .reel$ defina&le6 tags) article, title, author
F with !tart tag) <article>
etc'
F and end tag) </article> etc'
#lements) <article> </article>
lement! ha%e a name article6 and a content 6
lement! ma$ &e ne!ted' lement! ma$ &e empt$) <thisCisCem+t5/>
lement content i! t$picall$ par!ed character data @BA5A6,
i'e', !tring! with !pecial character!, andDor ne!ted element! !i*e&
content if &oth6' ach XML doc#ment ha! e-actl$ one root element and form! a
tree'
lement! with a common parent are ordered'
7/21/2019 XML for Beginners
http://slidepdf.com/reader/full/xml-for-beginners-56dbd85348518 22/55
Eleents %s' #ttributeslement! ma$ ha%e attributes in the !tart tag6 that ha%e a name and
a 'alue, e'g' <section number,=1=> '/hat i! the difference &etween element! and attri&#te!
Onl$ one attri&#te with a gi%en name per element &#t an ar&itrar$
n#m&er of !#&element!6
Attri&#te! ha%e no !tr#ct#re, !impl$ !tring! while element! canha%e !#&element!6
A! a r$le of th$!')
Bontent into element!
Metadata into attri&#te!
-ample)
<+erson born,=1$10%3= died,=1$"&0%07=>
2lan Turing</+erson> +ro#ed that
7/21/2019 XML for Beginners
http://slidepdf.com/reader/full/xml-for-beginners-56dbd85348518 23/55
XML ,ocuents as Or$ere$ /rees
article
author title text
sectionabstract
5he index
/e&
pro%ide! :
title,==
number,=1=
In order :
(erhard
/ei+#m
5he /e&
in 10 $ear!
7/21/2019 XML for Beginners
http://slidepdf.com/reader/full/xml-for-beginners-56dbd85348518 24/55
More on XML Syntax
Some !pecial character! m#!t &e e!caped #!ing entities
< DltED Dam+E
will &e con%erted &ac+ when reading the XML doc6
Some other character! ma$ &e e!caped, too)
> DgtE
= DFuotE
Da+osE
7/21/2019 XML for Beginners
http://slidepdf.com/reader/full/xml-for-beginners-56dbd85348518 25/55
0ell12ore$ XML ,ocuents
A well)formed doc#ment m#!t adher to, among other!, the
following r#le!) %er$ !tart tag ha! a matching end tag'
lement! ma$ ne!t, &#t m#!t not o%erlap'
5here m#!t &e e-actl$ one root element'
Attri&#te %al#e! m#!t &e G#oted'
An element ma$ not ha%e two attri&#te! with the !amename'
Bomment! and proce!!ing in!tr#ction! ma$ not appearin!ide tag!'
<o #ne!caped < or D !ign! ma$ occ#r in!ide characterdata'
7/21/2019 XML for Beginners
http://slidepdf.com/reader/full/xml-for-beginners-56dbd85348518 26/55
0ell12ore$ XML ,ocuents
A well)formed doc#ment m#!t adher to, among other!, the
following r#le!) %er$ !tart tag ha! a matching end tag'
lement! ma$ ne!t, &#t m#!t not o%erlap'
5here m#!t &e e-actl$ one root element'
Attri&#te %al#e! m#!t &e G#oted'
An element ma$ not ha%e to attri&#te! with the !amename'
Bomment! and proce!!ing in!tr#ction! ma$ not appearin!ide tag!'
<o #ne!caped < or D !ign! ma$ occ#r in!ide characterdata'
*nl" well)formed documentscan be processed b" XML
parsers+
7/21/2019 XML for Beginners
http://slidepdf.com/reader/full/xml-for-beginners-56dbd85348518 27/55
+'- 3aes!aces <librar5>
<descri+tion>ibrar5 o the : )e+artment</descri+tion>
<book bid,=Hand000=>
<title>Irinci+les o )ata ining</title>
<descri+tion>
hort introduction to <em>data mining</em>A useul
or the 9() course </descri+tion>
</book>
</librar5>
&emantics of t%e descri+tion element is ambigous$ontent ma" be defined differentl"
,enaming ma" be impossible (standards-
⇒ i!am&ig#ation of !eparate XML application! #!ing
#niG#e prefi-e!
7/21/2019 XML for Beginners
http://slidepdf.com/reader/full/xml-for-beginners-56dbd85348518 28/55
3aes!ace Syntax <dbs'book xmlns'dbs,=htt+'//...dbs/dbs=>
.niue .,0 to identif"
t%e namespaceSignal that name!pace
definition happen!
1refix as abbre'ation
of .,0
7/21/2019 XML for Beginners
http://slidepdf.com/reader/full/xml-for-beginners-56dbd85348518 29/55
3aes!ace Exa!le <dbs'book xmlns'dbs,=htt+'//...dbs/dbs=>
<dbs'descri+tion> </dbs'descri+tion>
<dbs'text>
<dbs'ormula>
<mathml'mathxmlns'mathml,=htt+'//....3org/1$$8/ath/ath=>
</mathml'math>
</dbs'ormula>
</dbs'text>
</dbs'book>
7/21/2019 XML for Beginners
http://slidepdf.com/reader/full/xml-for-beginners-56dbd85348518 30/55
,efault 3aes!ace
efa#lt name!pace ma$ &e !et for an element and it!
content &#t not it! attri&#te!6) <book xmlns,=htt+'//...dbs/dbs=>
<descri+tion></descri+tion>
<book>
Ban &e o%erridden in the element! &$ !pecif$ing thename!pace there #!ing prefi- or defa#lt name!pace6
7/21/2019 XML for Beginners
http://slidepdf.com/reader/full/xml-for-beginners-56dbd85348518 31/55
XML for Beginners
"art - – ,efining XML ,ata 2orats
3.1 Doc$!ent +%pe Definitions
3.2 XML Sche!a ,-er% short
- ( , t / , fi iti
7/21/2019 XML for Beginners
http://slidepdf.com/reader/full/xml-for-beginners-56dbd85348518 32/55
-'( ,ocuent /y!e ,efinitions
Sometime! XML i! too fle-i&le)
Mo!t @rogram! can onl$ proce!! a !#&!et of all po!!i&leXML application!
.or e-changing data, the format i'e', element!,
attri&#te! and their !emantic!6 m#!t &e fi-ed
⇒2ocument T"pe 2efinitions 2T26 for e!ta&li!hing the
%oca&#lar$ for one XML application in !ome !en!e
compara&le to sche!as in data&a!e!6
A doc#ment i! 'alid wit% respect to a 2T2 if it conform!to the r#le! !pecified in that 5'
Mo!t XML par!er! can &e config#red to %alidate'
,/, E l El t
7/21/2019 XML for Beginners
http://slidepdf.com/reader/full/xml-for-beginners-56dbd85348518 33/55
,/, Exa!le) Eleents <J;;;KT article ?titleAauthorLAtext@>
<J;;;KT title ?MI:)2T2@>
<J;;;KT author ?MI:)2T2@>
<J;;;KT text ?abstractAsectionNAliteratureO@>
<J;;;KT abstract ?MI:)2T2@>
<J;;;KT section ?MI:)2T2Pindex@L>
<J;;;KT literature ?MI:)2T2@> <J;;;KT index ?MI:)2T2@>
$ontent of t%e title element
is parsed c%aracter data
$ontent of t%e article element is a title element3
followed b" one or more author elements3
followed b" a text element
$ontent of t%e text element ma"
contain 4ero or more section
elements in t%is position
El t , l ti i ,/,
7/21/2019 XML for Beginners
http://slidepdf.com/reader/full/xml-for-beginners-56dbd85348518 34/55
Eleent ,eclarations in ,/,sOne element declaration for each element t$pe)
<J;;;KT elementCname contentCs+eciication>
where contentCs+eciication can &e
• ?MI:)2T2@ par!ed character data
• ?child@ one child element
•
?c1AAcn@ a !eG#ence of child element! c1:cn• ?c1PPcn@ one of the element! c1:cn
.or each component c, po!!i&le co#nt! can &e !pecified)
F c e-actl$ one !#ch element
F c one or more F cN zero or more
F c zero or one
@l#! ar&itrar$ com&ination! #!ing parenthe!i!)
<J;;;KT ??aPb@NAcLA?dPe@@N>
M El t , l ti
7/21/2019 XML for Beginners
http://slidepdf.com/reader/full/xml-for-beginners-56dbd85348518 35/55
More on Eleent ,eclarations
lement! with mi-ed content)
<J;;;KT text ?MI:)2T2PindexPcitePglossar5@N> lement! with empt$ content) <J;;;KT image ;ITY>
lement! with ar&itrar$ content thi! i! nothing for
prod#ction"le%el 5!6) <J;;;KT thesis 2KY>
#tt ib t , l ti i ,/,
7/21/2019 XML for Beginners
http://slidepdf.com/reader/full/xml-for-beginners-56dbd85348518 36/55
#ttribute ,eclarations in ,/,s
Attri&#te! are declared per element)
<J2TT9T section number :)2T2 M(;Q49(;) title :)2T2 M(;Q49(;)>
declare! two reG#ired attri&#te! for element section'
element name
attribute name
attribute t"pe
attribute default
#tt ib t , l ti i ,/,
7/21/2019 XML for Beginners
http://slidepdf.com/reader/full/xml-for-beginners-56dbd85348518 37/55
#ttribute ,eclarations in ,/,s
Attri&#te! are declared per element)
<J2TT9T section number :)2T2 M(;Q49(;) title :)2T2 M(;Q49(;)>
declare! two reG#ired attri&#te! for element section'
@o!!i&le attri&#te defa#lt!)
• M(;Q49(;) i! reG#ired in each element in!tance
• M9I9;) i! optional
• M*96;) deault alwa$! ha! thi! defa#lt %al#e• deault ha! thi! defa#lt %al#e if the attri&#te i!
omitted from the element in!tance
#tt ib t / i ,/,
7/21/2019 XML for Beginners
http://slidepdf.com/reader/full/xml-for-beginners-56dbd85348518 38/55
#ttribute /y!es in ,/,s• :)2T2 !tring data
•
?21PP2n@ en#meration of all po!!i&le %al#e! of theattri&#te each i! XML name6
• 9) #niG#e XML name to identif$ the element
•
9)(;* refer! to 9) attri&#te of !ome other element*intra"doc#ment lin+6
• 9)(;* li!t of 9)(;*, !eparated &$ white !pace
pl#! !ome more
#tt ib t E l
7/21/2019 XML for Beginners
http://slidepdf.com/reader/full/xml-for-beginners-56dbd85348518 39/55
#ttribute Exa!les <2TT9T +ublication t5+e ?!ournalPin+roceedings@ M(;Q49(;)
+ubid 9) M(;Q49(;)>
<2TT9T cite cid 9)(;* M(;Q49(;)> <2TT9T citation re 9)(;* M9I9;)
cid 9) M(;Q49(;)>
<+ublications>
<+ublication t5+e,=!ournal= +ubid,=Weikum01=>
<author>Gerhard Weikum</author>
<text>9n the Web o 010A 6 <cite cid,1=/></text>
<citation cid,1= re,6$8=/>
<citation cid,1"=></citation>
</+ublication>
<+ublication t5+e,=in+roceedings= +ubid,=6$8=>
<text>6A the extended arku+ anguageA </text>
</+ublication>
</+ublications>
#tt ib t E l
7/21/2019 XML for Beginners
http://slidepdf.com/reader/full/xml-for-beginners-56dbd85348518 40/55
#ttribute Exa!les <2TT9T +ublication t5+e ?!ournalPin+roceedings@ M(;Q49(;)
+ubid 9) M(;Q49(;)>
<2TT9T cite cid 9)(;* M(;Q49(;)> <2TT9T citation re 9)(;* M9I9;)
cid 9) M(;Q49(;)>
<+ublications>
<+ublication t5+e,=!ournal= +ubid,=Weikum01=>
<author>Gerhard Weikum</author>
<text>9n the Web o 010A 6 <cite cid,1=/></text>
<citation cid,1= re,6$8=/>
<citation cid,1"=></citation>
</+ublication>
<+ublication t5+e,=in+roceedings= +ubid,=6$8=>
<text>6A the extended arku+ anguageA </text>
</+ublication>
</+ublications>
Li ki ,/, $ XML ,
7/21/2019 XML for Beginners
http://slidepdf.com/reader/full/xml-for-beginners-56dbd85348518 41/55
Linking ,/, an$ XML ,ocs
oc#ment 5$pe eclaration in the XML doc#ment)
<J)R:TYI; article YT; =htt+'//...dbs/articledtd=>
ke"words ,oot element .,0 for t%e 2T2
Linking ,/, an$ XML ,ocs
7/21/2019 XML for Beginners
http://slidepdf.com/reader/full/xml-for-beginners-56dbd85348518 42/55
Linking ,/, an$ XML ,ocs
Internal 5)
<Oxml #ersion,=10=O> <J)R:TYI; article S
<J;;;KT article ?titleAauthorLAtext@>
<J;;;KT index ?MI:)2T2@>
>
<article>
</article>
Eoth wa$! can &e mi-ed, internal 5 o%erwrite!e-ternal entit$ information) <J)R:TYI; article YT; articledtd= S
<J;KT9TY U +ubCcontent ?titleLAauthorNAtext@
>
2laws of ,/,s
7/21/2019 XML for Beginners
http://slidepdf.com/reader/full/xml-for-beginners-56dbd85348518 43/55
2laws of ,/,s
<o !#pport for &a!ic data t$pe! li+e integer!, do#&le!,
date!, time!, : <o !tr#ct#red, !elf"defina&le data t$pe!
<o t$pe deri%ation
idDidref lin+! are G#ite loo!e target i! not !pecified6
⇒ XML Schema
- + XML Schea Basics
7/21/2019 XML for Beginners
http://slidepdf.com/reader/full/xml-for-beginners-56dbd85348518 44/55
-'+ XML Schea Basics
XML Schema i! an XML application
@ro%ide! !imple t$pe! !tring, integer, date5ime,d#ration, lang#age, :6
Allow! defining po!!i&le %al#e! for element!
Allow! defining t$pe! deri%ed from e-i!ting t$pe!
Allow! defining comple- t$pe!
Allow! po!ing con!traint! on the occ#rrence of element!
Allow! forcing #niG#ene!! and foreign +e$!
/a$ too comple- to co%er in an introd#ctor$ tal+
Si!lifie$ XML Schea Exa!le
7/21/2019 XML for Beginners
http://slidepdf.com/reader/full/xml-for-beginners-56dbd85348518 45/55
Si!lifie$ XML Schea Exa!le <xs'schema>
<xs'element name,=article=>
<xs'com+lexT5+e> <xs'seFuence>
<xs'element name,=author= t5+e,=xs'string=/>
<xs'element name,=title= t5+e,=xs'string=/>
<xs'element name,=text=>
<xs'com+lexT5+e>
<xs'seFuence>
<xs'element name,=abstract= t5+e,=xs'string=/>
<xs'element name,=section= t5+e,=xs'string=
minRccurs,=0= maxRccurs,=unbounded=/>
</xs'seFuence>
</xs'com+lexT5+e> </xs'element>
</xs'seFuence>
</xs'com+lexT5+e>
</xs'element>
</xs'schema>
7/21/2019 XML for Beginners
http://slidepdf.com/reader/full/xml-for-beginners-56dbd85348518 46/55
XML for Beginners
"art . – 4uerying XML ,ata
".1 X/ath
".2 X#$er%
4uerying XML with X"ath an$ X4uery
7/21/2019 XML for Beginners
http://slidepdf.com/reader/full/xml-for-beginners-56dbd85348518 47/55
4uerying XML with X"ath an$ X4uery
X@ath and XK#er$ are G#er$ lang#age! for XML data, &oth
!tandardized &$ the /3B and !#pported &$ %ario#! data&a!e prod#ct!'
5heir !earch capa&ilitie! incl#de logical conditions o%er element and attri&#te content
fir!t"order predicate logic a la SKL !imple condition! onl$ in X@ath6 regular expressions for pattern matching of element name!
along path! or !#&tree! within XML data Poin!, gro#ping, aggregation, tran!formation, etc' XK#er$ onl$6
In contra!t to data&a!e G#er$ lang#age! li+e SKL an XML G#er$
doe! not nece!!aril$ need to6 +now a fi-ed !tr#ct#ral !chemafor the #nderl$ing data'A uer" result i! a !et of G#alif$ing node!, path!, !#&tree!,or !#&graph! from the #nder$ling data graph,or a !et of XML doc#ment! con!tr#cted from thi! raw re!#lt'
. ( X"ath
7/21/2019 XML for Beginners
http://slidepdf.com/reader/full/xml-for-beginners-56dbd85348518 48/55
.'( X"ath
X@ath i! a !imple lang#age to identif$ part! of the XML
doc#ment for f#rther proce!!ing6 X@ath operate! on the tree repre!entation of the
doc#ment
Ce!#lt of an X@ath e-pre!!ion i! a !et of element! or
attri&#te!
i!c#!! a&&re%iated %er!ion of X@ath
Eleents of X"ath
7/21/2019 XML for Beginners
http://slidepdf.com/reader/full/xml-for-beginners-56dbd85348518 49/55
Eleents of X"ath
An X@ath e-pre!!ion #!#all$ i! a location pat% that
con!i!t! of location steps, !eparated &$ /)/article/text/abstract) !elect! all abstract element!
A leading / alwa$! mean! the root element
ach location !tep i! e%al#ated in the conte-t of a node
in the tree, the !o"called context node
@o!!i&le location !tep!)
F child element x) !elect all child element! with name x
F Attri&#te Vx) !elect all attri&#te! with name x F /ildcard! N an$ child6, VN an$ attri&#te6
F M#ltiple matche!, !eparated &$ P) xP5P
*obining Location Ste!s
7/21/2019 XML for Beginners
http://slidepdf.com/reader/full/xml-for-beginners-56dbd85348518 50/55
*obining Location Ste!s
Standard) / conte-t node i! the re!#lt of the preceding
location !tep6article/text/abstract all the a&!tract node! of article!6
Select an$ de!cendant, not onl$ children) //
article//index an$ inde- element in article!6
Select the parent element)
Select the content node)
5he latter two are important when #!ing predicates'
"re$icates in Location Ste!s
7/21/2019 XML for Beginners
http://slidepdf.com/reader/full/xml-for-beginners-56dbd85348518 51/55
"re$icates in Location Ste!s
Added with S to the location !tep
>!ed to re!trict! element! that G#alif$ a! re!#lt of alocation !tep to tho!e that f#lfil the predicate)– aSb element! a that ha%e a !#&element b
– aSVd element! a that ha%e an attri&#te d
F @l#! condition! on contentD%al#e)• aSb,c=
• 2SVd>7
• <A <,A >,A J,A
X"ath by Exa!le
7/21/2019 XML for Beginners
http://slidepdf.com/reader/full/xml-for-beginners-56dbd85348518 52/55
X"ath by Exa!le
Dliterat#reD&oo+Da#thor retrie%e! all &oo+ a#thor!)!tarting with the root, tra%er!e! the tree, matche! element
name! literat#re, &oo+, a#thor, and ret#rn! element!Qa#thorRS#ci#, anQDa#thorR,Qa#thorRA&ite&o#l, SergeQDa#thorR, ''',Qa#thorRQfir!tnameRJeffQDfir!tnameR Qla!tnameR>llmanQDla!tnameRQDa#thorR
Dliterat#reDNDa#thor a#thor! of &oo+!, article!, e!!a$!, etc'
Dliterat#reDDa#thor a#thor! that are de!cendant! of literat#re
Dliterat#reDD$ear %al#e of the $ear attri&#te of de!cendant! of literat#re
Dliterat#reDDa#thorfir!tname a#thor! that ha%e a !#&element fir!tname
Dliterat#reD&oo+Tarticle6Da#thor a#thor! of &oo+! or article!
Dliterat#reD&oo+price Q *80
Dliterat#reD&oo+a#thorDDco#ntr$ U *(erman$
low priced &oo+!
&oo+! with (erman a#thor
. + *ore *once!ts of X4uery
7/21/2019 XML for Beginners
http://slidepdf.com/reader/full/xml-for-beginners-56dbd85348518 53/55
.'+ *ore *once!ts of X4ueryXK#er$ i! an e-tremel$ powerf#l G#er$ lang#age for XML data'A G#er$ ha! the form of a !o"called .L/C e-pre!!ion)
*R( X#ar1 9K ex+r1A X#ar 9K ex+rA ;T X#ar3 ', ex+r3A X#ar& ', ex+r&A
WH;(; condition(;T4(K resultdocconstruction
5he .OC cla#!e e%al#ate! e-pre!!ion! which ma$ &e X@ath"!t$le path e-pre!!ion!6 and &ind! the re!#lting element! to %aria&le!'.or a gi%en &inding each %aria&le denote! e-actl$ one element'
5he L5 cla#!e &ind! entire !eG#ence! of element! to %aria&le!'
5he /4C cla#!e e%al#ate! a logical condition with each of the po!!i&le %aria&le &inding! and !elect! tho!e &inding! that!ati!f$ the condition'
5he C5>C< cla#!e con!tr#ct!, from each of the %aria&le &inding!,an XML re!#lt tree' 5hi! ma$ in%ol%e gro#ping and aggregation
and e%en complete !#&G#erie!'
X4uery Exa!les
7/21/2019 XML for Beginners
http://slidepdf.com/reader/full/xml-for-beginners-56dbd85348518 54/55
X4uery Exa!les // find Web-related articles by Dan Suciu from the year 1998
<results> *R( Xa 9K document?=literaturexml=@//article *R( Xn 9K Xa//authorA Xt 9K Xa/title WH;(; Xa/V5ear , =1$$8=
2K) contains?XnA =uciu=@ 2K) contains?XtA =Web=@(;T4(K <result> Xn Xt </result> Z </results>
// find articles co-authored by authors who have jointly written a book after 1995
<results> *R( Xa 9K document?=literaturexml=@//article *R( Xa1 9K Xa//authorA Xa 9K Xa//author
WH;(; R; Xb 9K document?=literaturexml=@// book 2T9*9; Xb//author , Xa1 2K) Xb//author , Xa 2K)
Xb/V5ear>=1$$"= (;T4(K <result> Xa1 Xa < .rote> Xa </ .rote> </result> Z
</results>
Suary an$ Outlook
7/21/2019 XML for Beginners
http://slidepdf.com/reader/full/xml-for-beginners-56dbd85348518 55/55
Suary an$ Outlook
Vo# !ho#ld gi%e one, I wonHt'