XML n Dtses Exm Prepertion Disuss Answers to lst yer s exm Sestin Mneth NICTA n UNSW CSE@UNSW -- Semester 1, 2008
(1) For eh of the following, explin why it is not well-forme XML (is WFC or the XML grmmr violte?) ) <uthor></uthor><title></title> ) <uthor><title></uthor></title> ) <info temp= 25C >ontent</info> ) <!DOCTYPE greeting [ <!ELEMENT greeting (#PCDATA)> <!ENTITY e1 "&e2; e3"> <!ENTITY e2 "&e3;"> <!ENTITY e3 "&e2;"> ]> <greeting> &e1; </greeting> e) < t1= lh t<2= foo > 1 < 5 </> f) < 3= 2= 1= 2= 5 /> g) <><><></></></>&e;</></> 2
(1) For eh of the following, explin why it is not well-forme XML (is WFC or the XML grmmr violte?) ) <uthor></uthor><title></title> XML grmmr (nnot e erive y grmmr!) ) <uthor><title></uthor></title> ) <info temp= 25C >ontent</info> ) <!DOCTYPE greeting [ <!ELEMENT greeting (#PCDATA)> <!ENTITY e1 "&e2; e3"> <!ENTITY e2 "&e3;"> <!ENTITY e3 "&e2;"> ]> <greeting> &e1; </greeting> e) < t1= lh t<2= foo > 1 < 5 </> f) < 3= 2= 1= 2= 5 /> g) <><><></></></>&e;</></> 3
(1) For eh of the following, explin why it is not well-forme XML (is WFC or the XML grmmr violte?) ) <uthor></uthor><title></title> XML grmmr ) <uthor><title></uthor></title> WFC ) <info temp= 25C >ontent</info> ) <!DOCTYPE greeting [ <!ELEMENT greeting (#PCDATA)> <!ENTITY e1 "&e2; e3"> <!ENTITY e2 "&e3;"> <!ENTITY e3 "&e2;"> ]> <greeting> &e1; </greeting> e) < t1= lh t<2= foo > 1 < 5 </> f) < 3= 2= 1= 2= 5 /> g) <><><></></></>&e;</></> 4
(1) For eh of the following, explin why it is not well-forme XML (is WFC or the XML grmmr violte?) ) <uthor></uthor><title></title> XML grmmr ) <uthor><title></uthor></title> WFC ) <info temp= 25C >ontent</info> XML grmmr (shoul e 25 ; -is tully OK..!) ) <!DOCTYPE greeting [ <!ELEMENT greeting (#PCDATA)> <!ENTITY e1 "&e2; e3"> <!ENTITY e2 "&e3;"> <!ENTITY e3 "&e2;"> ]> <greeting> &e1; </greeting> e) < t1= lh t<2= foo > 1 < 5 </> f) < 3= 2= 1= 2= 5 /> g) <><><></></></>&e;</></> 5
(1) For eh of the following, explin why it is not well-forme XML (is WFC or the XML grmmr violte?) ) <uthor></uthor><title></title> XML grmmr ) <uthor><title></uthor></title> WFC ) <info temp= 25C >ontent</info> XML grmmr (shoul e 25 ; -is tully OK..!) ) <!DOCTYPE greeting [ WFC <!ELEMENT greeting (#PCDATA)> <!ENTITY e1 "&e2; e3"> <!ENTITY e2 "&e3;"> <!ENTITY e3 "&e2;"> ]> <greeting> &e1; </greeting> e) < t1= lh t<2= foo > 1 < 5 </> f) < 3= 2= 1= 2= 5 /> g) <><><></></></>&e;</></> Well-formeness onstrint: No Reursion A prse entity MUST NOT ontin reursive referene to itself, either iretly or iniretly. 6
(1) For eh of the following, explin why it is not well-forme XML (is WFC or the XML grmmr violte?) ) <uthor></uthor><title></title> XML grmmr ) <uthor><title></uthor></title> WFC ) <info temp= 25C >ontent</info> XML grmmr (shoul e 25 ; -is tully OK..!) ) <!DOCTYPE greeting [ WFC <!ELEMENT greeting (#PCDATA)> <!ENTITY e1 "&e2; e3"> <!ENTITY e2 "&e3;"> <!ENTITY e3 "&e2;"> ]> <greeting> &e1; </greeting> e) < t1= lh t<2= foo > 1 < 5 </> XML grmmr f) < 3= 2= 1= 2= 5 /> g) <><><></></></>&e;</></> [41] Attriute ::= Nme Eq AttVlue [5] Nme ::= (Letter '_' ':') (NmeChr)* [84] Letter ::= [-za-z] 7
(1) For eh of the following, explin why it is not well-forme XML (is WFC or the XML grmmr violte?) ) <uthor></uthor><title></title> XML grmmr ) <uthor><title></uthor></title> WFC ) <info temp= 25C >ontent</info> XML grmmr (shoul e 25 ; -is tully OK..!) ) <!DOCTYPE greeting [ WFC <!ELEMENT greeting (#PCDATA)> <!ENTITY e1 "&e2; e3"> <!ENTITY e2 "&e3;"> <!ENTITY e3 "&e2;"> ]> <greeting> &e1; </greeting> e) < t1= lh t<2= foo > 1 < 5 </> XML grmmr f) < 3= 2= 1= 2= 5 /> WFC g) <><><></></></>&e;</></> Well-formeness onstrint: Unique Att Spe An ttriute nme MUST NOT pper more thn one in the sme strt-tg or empty-element tg. 8
(1) For eh of the following, explin why it is not well-forme XML (is WFC or the XML grmmr violte?) ) <uthor></uthor><title></title> XML grmmr ) <uthor><title></uthor></title> WFC ) <info temp= 25C >ontent</info> XML grmmr (shoul e 25 ; -is tully OK..!) ) <!DOCTYPE greeting [ WFC <!ELEMENT greeting (#PCDATA)> <!ENTITY e1 "&e2; e3"> <!ENTITY e2 "&e3;"> <!ENTITY e3 "&e2;"> ]> <greeting> &e1; </greeting> e) < t1= lh t<2= foo > 1 < 5 </> XML grmmr f) < 3= 2= 1= 2= 5 /> WFC g) <><><></></></>&e;</></> WFC Well-formeness onstrint: Entity Delre...the Nme given in the entity referene MUST mth tht in n entity elrtion tht... 9
(2) Show sequenes of Unioe hrters for whih ) UTF-8 nees more spe thn UTF-16 ) UTF-16 nees more spe thn UTF-8 together with the orresponing UTF oes n their lengths. ) Explin how to inry sort sequene of UTF-8 hrters. Use pseuo oe if pproprite. 10
(2) Show sequenes of Unioe hrters for whih ) UTF-8 nees more spe thn UTF-16 ) UTF-16 nees more spe thn UTF-8 together with the orresponing UTF oes n their lengths. ) Explin how to inry sort sequene of UTF-8 hrters. Use pseuo oe if pproprite. ) U+FFFF UTF-8: 11101111 10111111 10111111 = 24its UTF-16: 11111111 11111111 = 16its 11
(2) Show sequenes of Unioe hrters for whih ) UTF-8 nees more spe thn UTF-16 ) UTF-16 nees more spe thn UTF-8 together with the orresponing UTF oes n their lengths. ) Explin how to inry sort sequene of UTF-8 hrters. Use pseuo oe if pproprite. ) U+FFFF UTF-8: 11101111 10111111 10111111 = 24its UTF-16: 11111111 11111111 = 16its ) U+00 UTF-8: 00000000 = 8its UTF-16: 00000000 00000000 = 16its 12
(2) Show sequenes of Unioe hrters for whih ) UTF-8 nees more spe thn UTF-16 ) UTF-16 nees more spe thn UTF-8 together with the orresponing UTF oes n their lengths. ) Explin how to inry sort sequene of UTF-8 hrters. Use pseuo oe if pproprite. ) U+FFFF UTF-8: 11101111 10111111 10111111 = 24its UTF-16: 11111111 11111111 = 16its ) U+00 ) UTF-8: 00000000 = 8its UTF-16: 00000000 00000000 = 16its To inry ompre two hrters, simply strt from the highest it! In this wy, for hrters with ifferent lengths in UTF-8, fter 4 its we will e one! - In se UTF-8 lengths re sme norml inry ompre.. 13
(3) Show n element noe with mixe ontent, using the XML Informtion Set. Assume tht for noe M, Type(M) is it s type, i.e., is one of DOC, ELEM, ATTR, or CHAR. Using the Infoset, show pseuo oe tht, given noe N, ) returns ll nestors of the noe ) returns the previous siling of the noe. 14
(3) Show n element noe with mixe ontent, using the XML Informtion Set. Assume tht for noe M, Type(M) is it s type, i.e., is one of DOC, ELEM, ATTR, or CHAR. Using the Infoset, show pseuo oe tht, given noe N, ) returns ll nestors of the noe ) returns the previous siling of the noe. lolnme(e1) = elem hilren(e1) = [e2,1] lolnme(e2) = elem hilren(e2) = [] prent(e2) = e1 oe(1) = U+00 prent(1) = e1 ttriutes(e1) = [] ttriutes(e2) = [] 15
(3) Show n element noe with mixe ontent, using the XML Informtion Set. Assume tht for noe M, Type(M) is it s type, i.e., is one of DOC, ELEM, ATTR, or CHAR. Using the Infoset, show pseuo oe tht, given noe N, ) returns ll nestors of the noe ) returns the previous siling of the noe. lolnme(e1) = elem hilren(e1) = [e2,1] lolnme(e2) = elem hilren(e2) = [] prent(e2) = e1 oe(1) = U+00 prent(1) = e1 ttriutes(e1) = [] ttriutes(e2) = [] ) getanestors(noe n): NoeSet { NoeSet result=null; } if(n.type!=doc){ for(; n=n->prent ; n.type!= DOC ) A(n,result); A(n,result); } return result; 16
(3) Show n element noe with mixe ontent, using the XML Informtion Set. Assume tht for noe M, Type(M) is it s type, i.e., is one of DOC, ELEM, ATTR, or CHAR. Using the Infoset, show pseuo oe tht, given noe N, ) returns ll nestors of the noe ) returns the previous siling of the noe. lolnme(e1) = elem hilren(e1) = [e2,1] lolnme(e2) = elem hilren(e2) = [] prent(e2) = e1 oe(1) = U+00 prent(1) = e1 ttriutes(e1) = [] ttriutes(e2) = [] ) getanestors(noe n): NoeSet { NoeSet result=null; ) getprevsi(noe n): Noe { NoeList l=null; if(n.type!= DOC ) { Noe prent=n->prentnoe(); l=n->hilren; if(l==null) return NULL; s=first(l); if(s==l) return NULL; while(s->next!=n) s=s->next(); } return s; } } if(n.type!=doc){ for(; n=n->prent ; n.type!= DOC ) A(n,result); A(n,result); } return result; 17
(4) Using DOM, give pseuo oe tht etermines the verge epth of the XML tree. The verge epth of </> is 1. 18
(4) Using DOM, give pseuo oe tht etermines the verge epth of the XML tree. The verge epth of </> is 1. int totl=0; int ount=0; ll laverge(root, 1); return totl/ount; voi laverge(noe n, int epth) { NoeList hilren = n->hillist(); if(hilren->isempty()) { totl += epth; ount++; return; } else for eh Noe in hilren laverge(, epth+1); } 19
(5) Explin in etil, using n exmple, why hshing is useful for fining the miniml DAG of tree. Why re uptes more expensive on DAG thn on tree? Give n exmple tht lerly explins this. 20
(5) Explin in etil, using n exmple, why hshing is useful for fining the miniml DAG of tree. Why re uptes more expensive on DAG thn on tree? Give n exmple tht lerly explins this. When omputing the miniml DAG, we nee to etermine whether given sutree hs ourre lrey. If we keep tle of pointers to the sutrees tht hve ourre lrey, then to hek for given sutree whether or not it ours in the tle tkes in the worst se (#of trees in the tle) x (# noes in sutree) whih, in the worst se, is qurti to the size of the input tree! With hshing, we only nee (# trees in the hsh uket) x (# noes in the sutree). Thus, if uket hs only onstnt numer of trees, on verge, then the omplexity goes from qurti to liner! Exmple tree: k Seen:=NULL Seen:=seen + -tree Contins(Seen, -tree )? nees 1 omprison Seen:=Seen + -tree Contins(Seen, -tree )? nees 2 omprisons Seen:=Seen + -tree Contins(Seen, -tree )? nees 3 omprisons Seen:=Seen + -tree Assume hsh( -tree )=1 hsh( -tree )=2 hsh( -tree )=3 hsh( -tree )=4 Then we nee no (tree) omprisons whtsover! 21
(5) Explin in etil, using n exmple, why hshing is useful for fining the miniml DAG of tree. Why re uptes more expensive on DAG thn on tree? Give n exmple tht lerly explins this. DAG 1: 2: [1,1,1] Duplite noe 2 DAG Insert(2, -tree ) DAG 1: 2: 3: [1,2,1] 1: 2: 3: [2] 4: [1,3,1] Inserting single new hil require ing two rows n hnging one existing one. (the shre 2 n hil -sutree of the -noe must e uplite first, efore the -hil n e e. 22
(6) Give the PRE/POST tle for the tree <><></></><></><></></></></></><><></></></></> </></> ) Give pseuo oe tht omputes the POST orer of tree in n itertive wy, i.e., without ny reursive lls(!). You n use firstchil(n), nextsiling(n), n prent(n) for noe n. Using the PRE/POST-enoing, explin how to otin ) the nestors of noe ) the lst hil of noe e) the mximl epth of the sutree t noe. 23
(6) Give the PRE/POST tle for the tree <><></></><></><></></></></></><><></></></></> </></> ) Give pseuo oe tht omputes the POST orer of tree in n itertive wy, i.e., without ny reursive lls(!). You n use firstchil(n), nextsiling(n), n prent(n) for noe n. Using the PRE/POST-enoing, explin how to otin ) the nestors of noe ) the lst hil of noe e) the mximl epth of the sutree t noe. 2 3 1 4 9 10 5 6 11 14 7 8 12 13 PRE POST lel 1 14 2 2 3 1 4 7 5 3 6 6 7 4 8 5 9 8 10 13 11 11 12 12 13 10 14 12 24
(6) Give the PRE/POST tle for the tree <><></></><></><></></></></></><><></></></></> </></> ) Give pseuo oe tht omputes the POST orer of tree in n itertive wy, i.e., without ny reursive lls(!). You n use firstchil(n), nextsiling(n), n prent(n) for noe n. Using the PRE/POST-enoing, explin how to otin ) the nestors of noe ) the lst hil of noe e) the mximl epth of the sutree t noe. ) int i=1; Noe n=root; repet{ while(firstchil(n)!=null) n=firstchil(n); post(i)=n; i++; while(nextsiling(n)==nil){ n=prent(n); if(n==null) rek; post(i)=n; i++; } n=nextsiling(n); } 25
(6) Give the PRE/POST tle for the tree <><></></><></><></></></></></><><></></></></> </></> ) Give pseuo oe tht omputes the POST orer of tree in n itertive wy, i.e., without ny reursive lls(!). You n use firstchil(n), nextsiling(n), n prent(n) for noe n. Using the PRE/POST-enoing, explin how to otin ) the nestors of noe ) the lst hil of noe e) the mximl epth of the sutree t noe. ) Given (pre, post) of noe, its nestors re ll noes with pre-vlue < pre n post-vlue > post. 26
(6) Give the PRE/POST tle for the tree <><></></><></><></></></></></><><></></></></> </></> ) Give pseuo oe tht omputes the POST orer of tree in n itertive wy, i.e., without ny reursive lls(!). You n use firstchil(n), nextsiling(n), n prent(n) for noe n. Using the PRE/POST-enoing, explin how to otin ) the nestors of noe ) the lst hil of noe e) the mximl epth of the sutree t noe. ) Given (pre, post) of noe, its nestors re ll noes with pre-vlue < pre n post-vlue > post. ) If there i noe with pre-vlue > pre n with post-vlue=post-1, then tht is the lst hil of (pre, post) 27
(6) Give the PRE/POST tle for the tree <><></></><></><></></></></></><><></></></></> </></> ) Give pseuo oe tht omputes the POST orer of tree in n itertive wy, i.e., without ny reursive lls(!). You n use firstchil(n), nextsiling(n), n prent(n) for noe n. Using the PRE/POST-enoing, explin how to otin ) the nestors of noe ) the lst hil of noe e) the mximl epth of the sutree t noe. ) Given (pre, post) of noe, its nestors re ll noes with pre-vlue < pre n post-vlue > post. ) If there i noe with pre-vlue > pre n with post-vlue=post-1, then tht is the lst hil of (pre, post) e) int mxdepth(int pr){ size(int p): int{ int s=0; for(int pr2=p+1; post(pr2)<post(p); pr2++) s++ return s; } int D=0; int u,l; L=pr+size(pr)-post(pr); for(int pr2=pr+1; post(pr2)<post(pr); pr2++){ u=pr2+size(pr2)-post(pr2)-l; if(u>d) D=u; return D; } 28
(8) Show the Glushkov utomton for the regulr expression E=( )*. Is this expression 1-unmiguous? Explin! Give eterministi utomton for the sme expression. Is E2=(*( ))* equivlent to E? Is it 1-unmiguous? Show 1-unmiguous expression tht is equivlent to ( )*. 29
(8) Show the Glushkov utomton for the regulr expression E=( )*. Is this expression 1-unmiguous? Explin! Give eterministi utomton for the sme expression. Is E2=(*( ))* equivlent to E? Is it 1-unmiguous? Show 1-unmiguous expression tht is equivlent to ( )*. Deterministi?? 30
(8) Show the Glushkov utomton for the regulr expression E=( )*. Is this expression 1-unmiguous? Explin! Give eterministi utomton for the sme expression. Is E2=(*( ))* equivlent to E? Is it 1-unmiguous? Show 1-unmiguous expression tht is equivlent to ( )*. Deterministi?? no! Thus, E is not 1-unmiguous. 31
(8) Show the Glushkov utomton for the regulr expression E=( )*. Is this expression 1-unmiguous? Explin! Give eterministi utomton for the sme expression. Is E2=(*( ))* equivlent to E? Is it 1-unmiguous? Show 1-unmiguous expression tht is equivlent to ( )*. Deterministi utomton: 32
(8) Show the Glushkov utomton for the regulr expression E=( )*. Is this expression 1-unmiguous? Explin! Give eterministi utomton for the sme expression. Is E2=(*( ))* equivlent to E? Is it 1-unmiguous? Show 1-unmiguous expression tht is equivlent to ( )*. NOT equivlent to E! The string is mthe y E, ut NOT y E2. E2 is NOT 1-unmiguous: 33
(8) Show the Glushkov utomton for the regulr expression E=( )*. Is this expression 1-unmiguous? Explin! Give eterministi utomton for the sme expression. Is E2=(*( ))* equivlent to E? Is it 1-unmiguous? Show 1-unmiguous expression tht is equivlent to ( )*. The expression *(*)* is equivlent to E 1-unmiguous. 34
(9) For the tree given in 6, write XPth expressions tht ) selet ll noes ) selet ll noes tht hve -hil ) selet ll noes tht hve no -hilren ) selet the right most -noe e) selet ll noes tht hve -prent <><></></><></><></></></></></><><></></></></> </></> 1: 2: 4: 9: 10: 3: 5: 6: 11: 14: Wth out! This is typo on your Exm printout.. Sorry. 7: 8: 12: 13: 35
(9) For the tree given in 6, write XPth expressions tht ) selet ll noes ) selet ll noes tht hve -hil ) selet ll noes tht hve no -hilren ) selet the right most -noe e) selet ll noes tht hve -prent <><></></><></><></></></></></><><></></></></> </></> 1: ) // 2: 4: 9: 10: 3: 5: 6: 11: 14: 7: 8: 12: 13: 36
(9) For the tree given in 6, write XPth expressions tht ) selet ll noes ) selet ll noes tht hve -hil ) selet ll noes tht hve no -hilren ) selet the right most -noe e) selet ll noes tht hve -prent <><></></><></><></></></></></><><></></></></> </></> 1: 2: 4: 9: 10: ) // ) //[] 3: 5: 6: 11: 14: 7: 8: 12: 13: 37
(9) For the tree given in 6, write XPth expressions tht ) selet ll noes ) selet ll noes tht hve -hil ) selet ll noes tht hve no -hilren ) selet the right most -noe e) selet ll noes tht hve -prent <><></></><></><></></></></></><><></></></></> </></> 1: 2: 4: 9: 10: ) // ) //[] 3: 5: 6: 11: 14: ) //[not()] 7: 8: 12: 13: 38
(9) For the tree given in 6, write XPth expressions tht ) selet ll noes ) selet ll noes tht hve -hil ) selet ll noes tht hve no -hilren ) selet the right most -noe (noe no 11) e) selet ll noes tht hve -prent <><></></><></><></></></></></><><></></></></> </></> 1: 2: 4: 9: 10: 3: 5: 6: 7: 8: 11: 12: 14: 13: ) // ) //[] ) //[not()] ) //[] or //[ n ] 39
(9) For the tree given in 6, write XPth expressions tht ) selet ll noes ) selet ll noes tht hve -hil ) selet ll noes tht hve no -hilren ) selet the right most -noe (noe no 11) e) selet ll noes tht hve -prent <><></></><></><></></></></></><><></></></></> </></> 1: 2: 4: 9: 10: 3: 5: 6: 7: 8: 11: 12: 14: 13: ) // ) //[] ) //[not()] ) //[] or //[ n ] e) //*[prent::] or ///* 40
(10) Below is tree orresponing to the oument in (6). Show the sequenes of noe numers tht re selete y the following queries. ) //// ) //*[ or ] ) ///nestor::/following:: ) //*[not(.//./nestor::)] e) /////preeing::*// 1: 2: 4: 9: 10: 3: 5: 6: 11: 14: 7: 8: 12: 13: 41
(10) Below is tree orresponing to the oument in (6). Show the sequenes of noe numers tht re selete y the following queries. ) //// ) //*[ or ] ) ///nestor::/following:: ) //*[not(.//./nestor::)] e) /////preeing::*// 1: ) 5, 6, 13 2: 4: 9: 10: 3: 5: 6: 11: 14: 7: 8: 12: 13: 42
(10) Below is tree orresponing to the oument in (6). Show the sequenes of noe numers tht re selete y the following queries. ) //// ) //*[ or ] ) ///nestor::/following:: ) //*[not(.//./nestor::)] e) /////preeing::*// 1: 2: 4: 9: 10: ) 5, 6, 13 ) 1, 6, 11 3: 5: 6: 11: 14: 7: 8: 12: 13: 43
(10) Below is tree orresponing to the oument in (6). Show the sequenes of noe numers tht re selete y the following queries. ) //// ) //*[ or ] ) ///nestor::/following:: ) //*[not(.//./nestor::)] e) /////preeing::*// 1: 2: 4: 9: 10: 3: 5: 6: 11: 14: ) 5, 6, 13 ) 1, 6, 11 ) 9, 13, 14 7: 8: 12: 13: 44
(10) This tree orresponing to the XML in (6). Show the sequenes of noe numers tht re selete y the following queries. ) //// ) //*[ or ] ) ///nestor::/following:: ) //*[not(.//./nestor::)] e) /////preeing::*// 1: 2: 4: 9: 10: 3: 5: 6: 11: 14: ) 5, 6, 13 ) 1, 6, 11 ) 9, 13, 14 ) 2, 3, 9, 14 7: 8: 12: 13: 45
(10) This tree orresponing to the XML in (6). Show the sequenes of noe numers tht re selete y the following queries. ) //// ) //*[ or ] ) ///nestor::/following:: ) //*[not(.//./nestor::)] e) /////preeing::*// 1: 2: 4: 9: 10: 3: 5: 6: 11: 14: ) 5, 6, 13 ) 1, 6, 11 ) 9, 13, 14 ) 2, 3, 9, 14 7: 8: 12: 13: e) 5, 6 46
(10) This tree orresponing to the XML in (6). ) ///nestor::/following:: ) //*[not(.//./nestor::)] For query ) show in etil how the Core-XPth evlution lgorithm omputes the nswer to this query. Do the sme for query ). 0:root 1: 2: 4: 9: 10: 3: 5: 6: 11: 14: Å following l() Å nestor l() 7: 8: 12: l() = { 1 } l() = { 2, 7, 8, 10, 12 } l() = { 3, 4, 11 } l() = { 5, 6, 9, 13, 14 } 13: esennt { root } Å l() 47
(10) This tree orresponing to the XML in (6). ) ///nestor::/following:: ) //*[not(.//./nestor::)] For query ) show in etil how the Core-XPth evlution lgorithm omputes the nswer to this query. Do the sme for query ). 0:root 1: 2: 4: 9: 10: 3: 5: 6: 11: 14:? Å following l() Å {5,6,9,13,14} nestor l() 7: 8: 12: l() = { 1 } l() = { 2, 7, 8, 10, 12 } l() = { 3, 4, 11 } l() = { 5, 6, 9, 13, 14 } 13: Å {1,2,..,14} esennt { root } {0} l() {2,7,8,10,12} 48
(10) This tree orresponing to the XML in (6). ) ///nestor::/following:: ) //*[not(.//./nestor::)] For query ) show in etil how the Core-XPth evlution lgorithm omputes the nswer to this query. Do the sme for query ). 0:root 1: 2: 4: 9: 10: 3: 5: 6: 11: 14: Å following l() {0,1,4,6,10,11} Å {5,6,9,13,14} nestor l() 7: 8: 12: l() = { 1 } l() = { 2, 7, 8, 10, 12 } l() = { 3, 4, 11 } l() = { 5, 6, 9, 13, 14 } 13: Å {1,2,..,14} esennt { root } {0} l() {2,7,8,10,12} 49
(10) This tree orresponing to the XML in (6). ) ///nestor::/following:: ) //*[not(.//./nestor::)] For query ) show in etil how the Core-XPth evlution lgorithm omputes the nswer to this query. Do the sme for query ). 0:root 1: 2: 4: 9: 10: 3: 5: 6: 11: 14: Å following l() {0,1,4,6,10,11} {6} Å {5,6,9,13,14} nestor l() 7: 8: 12: l() = { 1 } l() = { 2, 7, 8, 10, 12 } l() = { 3, 4, 11 } l() = { 5, 6, 9, 13, 14 } 13: Å {1,2,..,14} esennt { root } {0} l() {2,7,8,10,12} 50
(10) This tree orresponing to the XML in (6). ) ///nestor::/following:: ) //*[not(.//./nestor::)] For query ) show in etil how the Core-XPth evlution lgorithm omputes the nswer to this query. Do the sme for query ). 0:root 1: 2: 4: 9: 10: 3: 5: 6: 11: 14: {9,13,14} Å {9,10,..,14} {5,6,9,13,14} following l() {0,1,4,6,10,11} {6} Å {5,6,9,13,14} nestor l() 7: 8: 12: l() = { 1 } l() = { 2, 7, 8, 10, 12 } l() = { 3, 4, 11 } l() = { 5, 6, 9, 13, 14 } 13: Å {1,2,..,14} esennt { root } {0} l() {2,7,8,10,12} 51
(10) This tree orresponing to the XML in (6). ) ///nestor::/following:: ) //*[not(.//./nestor::)] For query ) show in etil how the Core-XPth evlution lgorithm omputes the nswer to this query. Do the sme for query ). 0:root 1: {1,2,..,14} Å esennt l(*) 2: 4: 9: 10: {1,2,..,14} { root } 3: 5: 6: 11: 14: {0} 7: 8: 12: 13: l() = { 1 } l() = { 2, 7, 8, 10, 12 } l() = { 3, 4, 11 } l() = { 5, 6, 9, 13, 14 } 52
(10) This tree orresponing to the XML in (6). ) ///nestor::/following:: ) //*[not(.//./nestor::)] For query ) show in etil how the Core-XPth evlution lgorithm omputes the nswer to this query. Do the sme for query ). 0:root 1: {1,2,..,14} Å esennt l(*) 2: 4: 9: 10: {1,2,..,14} { root } 3: 5: 6: 11: 14: {0} Å - 7: 8: 12: l() = { 1 } l() = { 2, 7, 8, 10, 12 } l() = { 3, 4, 11 } l() = { 5, 6, 9, 13, 14 } 13: om nestor l() esennt l() {2,7,8,10,12} {3,4,11} 53
(10) This tree orresponing to the XML in (6). ) ///nestor::/following:: ) //*[not(.//./nestor::)] For query ) show in etil how the Core-XPth evlution lgorithm omputes the nswer to this query. Do the sme for query ). 0:root 1: {1,2,..,14} Å esennt l(*) 2: 4: 9: 10: {1,2,..,14} { root } 3: 5: 6: 11: 14: {0} Å - 7: 8: 12: l() = { 1 } l() = { 2, 7, 8, 10, 12 } l() = { 3, 4, 11 } l() = { 5, 6, 9, 13, 14 } 13: om {5-8,12,13} {1,4,6,10,11} nestor esennt l() l() {2,7,8,10,12} {3,4,11} 54
(10) This tree orresponing to the XML in (6). ) ///nestor::/following:: ) //*[not(.//./nestor::)] For query ) show in etil how the Core-XPth evlution lgorithm omputes the nswer to this query. Do the sme for query ). 0:root 1: {1,2,..,14} Å esennt l(*) 2: 4: 9: 10: {1,2,..,14} { root } 3: 5: 6: 11: 14: {0} 7: 8: 12: l() = { 1 } l() = { 2, 7, 8, 10, 12 } l() = { 3, 4, 11 } l() = { 5, 6, 9, 13, 14 } 13: {0-14} om {1,4,6,10,11} Å - nestor {1,4-8,10-13} {5-8,12,13} esennt l() l() {2,7,8,10,12} {3,4,11} 55
(10) This tree orresponing to the XML in (6). ) ///nestor::/following:: ) //*[not(.//./nestor::)] For query ) show in etil how the Core-XPth evlution lgorithm omputes the nswer to this query. Do the sme for query ). 0:root 1: {1,2,..,14} Å esennt l(*) 2: 4: 9: 10: {1,2,..,14} { root } 3: 5: 6: 11: 14: {0} {0-14} 7: 8: 12: 13: om l() = { 1 } l() = { 2, 7, 8, 10, 12 } l() = { 3, 4, 11 } l() = { 5, 6, 9, 13, 14 } {1,4,6,10,11} Å - nestor {0,2,3,9,14} {1,4-8,10-13} {5-8,12,13} esennt l() l() {2,7,8,10,12} {3,4,11} 56
(10) This tree orresponing to the XML in (6). ) ///nestor::/following:: ) //*[not(.//./nestor::)] For query ) show in etil how the Core-XPth evlution lgorithm omputes the nswer to this query. Do the sme for query ). 0:root 1: {1,2,..,14} Å esennt l(*) 2: 4: 9: 10: {1,2,..,14} { root } 3: 5: 6: 11: 14: {0} {0-14} 7: 8: 12: 13: om l() = { 1 } l() = { 2, 7, 8, 10, 12 } l() = { 3, 4, 11 } l() = { 5, 6, 9, 13, 14 } {1,4,6,10,11} Å - nestor {2,3,9,14} {0,2,3,9,14} {1,4-8,10-13} {5-8,12,13} esennt l() l() {2,7,8,10,12} {3,4,11} 57
(11) Show n exmple of XPth queries q1,q2 suh tht they re not equivlent, ut q1 is inlue in q2. Show tht q1 is inlue in q2 using one of the methos isusse. Use the homomorphism tehnique to test whether p=[.//[/*//]/[//]/[/]] is inlue in q=[.//[//*//]/*[/]] 58
(11) Show n exmple of XPth queries q1,q2 suh tht they re not equivlent, ut q1 is inlue in q2. Show tht q1 is inlue in q2 using one of the methos isusse. Use the homomorphism tehnique to test whether p=[.//[/*//]/[//]/[/]] is inlue in q=[.//[//*//]/*[/]] q1 = /// q2 = // or q1 = // q2 = //* 59
(11) Show n exmple of XPth queries q1,q2 suh tht they re not equivlent, ut q1 is inlue in q2. Show tht q1 is inlue in q2 using one of the methos isusse. Use the homomorphism tehnique to test whether p=[.//[/*//]/[//]/[/]] is inlue in q=[.//[//*//]/*[/]] q1 = /// q2 = // Cnonil moel: Reple in q1 // y N+1 mny /z/ 0, here z Do they mth q2? yes!! or q1 = // q2 = //* 60
(11) Show n exmple of XPth queries q1,q2 suh tht they re not equivlent, ut q1 is inlue in q2. Show tht q1 is inlue in q2 using one of the methos isusse. Use the homomorphism tehnique to test whether p=[.//[/*//]/[//]/[/]] is inlue in q=[.//[//*//]/*[/]] * * * 61
(11) Show n exmple of XPth queries q1,q2 suh tht they re not equivlent, ut q1 is inlue in q2. Show tht q1 is inlue in q2 using one of the methos isusse. Use the homomorphism tehnique to test whether p=[.//[/*//]/[//]/[/]] is inlue in q=[.//[//*//]/*[/]] * * * 62
(11) Show n exmple of XPth queries q1,q2 suh tht they re not equivlent, ut q1 is inlue in q2. Show tht q1 is inlue in q2 using one of the methos isusse. Use the homomorphism tehnique to test whether p=[.//[/*//]/[//]/[/]] is inlue in q=[.//[//*//]/*[/]] * * * 63
(11) Show n exmple of XPth queries q1,q2 suh tht they re not equivlent, ut q1 is inlue in q2. Show tht q1 is inlue in q2 using one of the methos isusse. Use the homomorphism tehnique to test whether p=[.//[/*//]/[//]/[/]] is inlue in q=[.//[//*//]/*[/]] * * * 64
(11) Show n exmple of XPth queries q1,q2 suh tht they re not equivlent, ut q1 is inlue in q2. Show tht q1 is inlue in q2 using one of the methos isusse. Use the homomorphism tehnique to test whether p=[.//[/*//]/[//]/[/]] is inlue in q=[.//[//*//]/*[/]] * * * 65
(11) Show n exmple of XPth queries q1,q2 suh tht they re not equivlent, ut q1 is inlue in q2. Show tht q1 is inlue in q2 using one of the methos isusse. Use the homomorphism tehnique to test whether p=[.//[/*//]/[//]/[/]] is inlue in q=[.//[//*//]/*[/]] * * * Cn not e mppe. 66
(11) Show n exmple of XPth queries q1,q2 suh tht they re not equivlent, ut q1 is inlue in q2. Show tht q1 is inlue in q2 using one of the methos isusse. Use the homomorphism tehnique to test whether p=[.//[/*//]/[//]/[/]] is inlue in q=[.//[//*//]/*[/]] * * * Cn not e mppe. Note: p is inlue in q!! 67
(11) Show n exmple of XPth queries q1,q2 suh tht they re not equivlent, ut q1 is inlue in q2. Show tht q1 is inlue in q2 using one of the methos isusse. Use the homomorphism tehnique to test whether p=[.//[/*//]/[//]/[/]] is inlue in q=[.//[//*//]/*[/]] * * * Cse 1: hs -hil Why? Cse 2: hs no -hil Note: p is inlue in q!! 68
(11) Show n exmple of XPth queries q1,q2 suh tht they re not equivlent, ut q1 is inlue in q2. Show tht q1 is inlue in q2 using one of the methos isusse. Use the homomorphism tehnique to test whether p=[.//[/*//]/[//]/[/]] is inlue in q=[.//[//*//]/*[/]] OK!! p inlue in q, for Cse 1! * * * Cse 1: hs -hil Why? Cse 2: hs no -hil Note: p is inlue in q!! 69
(11) Show n exmple of XPth queries q1,q2 suh tht they re not equivlent, ut q1 is inlue in q2. Show tht q1 is inlue in q2 using one of the methos isusse. Use the homomorphism tehnique to test whether p=[.//[/*//]/[//]/[/]] is inlue in q=[.//[//*//]/*[/]] Also OK!! p inlue in q, for Cse 2! * * * * Cse 2: hs no -hil Why? Note: p is inlue in q!! 70
(12) Construt DTD suh tht 10) is inlue in 10e), n nother DTD suh tht 10e) is inlue in 10). [Very esy!!] 10) //// 10e) /////preeing::*// 71
(12) Construt DTD suh tht 10) is inlue in 10e), n nother DTD suh tht 10e) is inlue in 10). [Very esy!!] 10) //// 10e) /////preeing::*// For the first prt: *Any DTD* so tht -noes o NOT hve -esennts! For the seon prt: Any DTD, so tht ll -noes re -esennts. 72
(14) Given PRE/POST/SIZE tle, show SQL queries for the XPth queries ) /* ) ///* ) ///*// ) ///following-siling:: 73
(14) Given PRE/POST/SIZE tle, show SQL queries for the XPth queries ) /* ) ///* ) ///*// ) ///following-siling:: SELECT DISTINCT r1.pre FROM o_tl r1 WHERE r1.pre=1 ORDERED BY r1.pr 74
(14) Given PRE/POST/SIZE tle, show SQL queries for the XPth queries ) /* ) ///* ) ///*// ) ///following-siling:: SELECT DISTINCT r4.pre FROM o_tl r1, r2, r3, r4 WHERE r1.pre=0 AND r2.pre>r1.pre AND r2.post<r1.post AND (r2.pre-r2.post+r2.size)=(r1.pre-r1.post+r1.size)+1 AND r2.tg= AND r3.pre>r2.pre AND r3.post<r2.post AND (r3.pre-r3.post+r3.size)=(r2.pre-r2.post+r2.size)+1 AND r3.tg= AND r4.pre>r3.pre AND r4.post<r3.post AND (r4.pre-r4.post+r4.size)=(r3.pre-r3.post+r3.size)+1 ORDERED BY r4.pre Rell: level(n) = pre(n) post(n)+size(n) 75
(14) Given PRE/POST/SIZE tle, show SQL queries for the XPth queries ) /* ) ///* ) ///*// ) ///following-siling:: SELECT DISTINCT r4.pre FROM o_tl r1, r2, r3, r4 WHERE r1.pre=0 AND r2.pre>r1.pre AND r2.post<r1.post AND r2.tg= AND r3.pre>r2.pre AND r3.post<r2.post AND (r3.pre-r3.post+r3.size)=(r2.pre-r2.post+r2.size)+1 AND r4.pre>r3.pre AND r4.post<r3.post AND r4.tg= ORDERED BY r4.pre Rell: level(n) = pre(n) post(n)+size(n) 76
(14) Given PRE/POST/SIZE tle, show SQL queries for the XPth queries ) /* ) ///* ) ///*// ) ///following-siling:: SELECT DISTINCT r4.pre FROM o_tl r1, r2, r3, r4 WHERE r1.pre=0 AND r2.pre>r1.pre AND r2.post<r1.post AND r2.tg= AND r3.pre<r2.pre AND r3.post>r2.post AND (r3.pre-r3.post+r3.size)=(r2.pre-r2.post+r2.size)-1 AND r4.pre>r2.pre AND r4.post<r3.post AND (r4.pre-r4.post+r4.size)=(r2.pre-r2.post+r2.size) AND r4.tg= ORDERED BY r4.pre prent of -noe fter efore prent sme level s Rell: level(n) = pre(n) post(n)+size(n) 77