










Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Notes; Class: Database Systems I; Subject: Computer Science; University: University of California-Santa Cruz; Term: Unknown 2003;
Typology: Study notes
1 / 18
This page cannot be seen from the preview
Don't miss anything!











Winter 2003 1
University of Pennsylvania (by Peter Buneman and Susan Davidson)
Winter 2003 2
Programming with XML
Winter 2003 3
Winter 2003 4
DOM – t h e Do c u m e n t Ob j e c t Mo d e l
http://www.w3.org/DOM/
Winter 2003 7
public interface NodeList { public Node item(int index); public int getLength(); }
public interface NamedNodeMap { public Node getNamedItem(String name); ... }
Sub-e l e m e n t s --a n “a r ra y ”
A tt r ibut e s -- a “d ic t io n a r y ”
Winter 2003 8
John Doe 123 7456 Jane Dee 234 5678 … ...
F in d t h e n a m e s a n d te le p h o n e s o f a ll e m p lo y e e s in M a th
Winter 2003 9
public class Test
{
public static void main(String args[]) throws Exception { Parser parser = new Parser( args[0] ); Document doc = parser.readStream( new FileInputStream( args[0] )); NodeList nodes = doc.getDocumentElement.getChildNodes(); for (int i=0; i<nodes.getLength(); i++) { Node n = nodes.item(i); //coercion // select Math depts } }
}
Winter 2003 10
S e le c t in g t h e m a t h d e p a r t m e n t s
NodeList ndl = n.getChildNodes(); for(int idl=0; idl<ndl.getLength(); idl++) { Node nd = ndl.item(idl); if ((nd.tagName = "dept") &&
(((CharacterData) (nd.getFirstChild)).getData=“Math")) // coercion { //inner code return;
} }
Winter 2003 13
Winter 2003 14
Document d = new DocumentImplementation … Element root = d.createElement(“doc2”) // set root of document //top level loop { Element emp = d.createElement(“employee”) root.appendChild(emp) //innermost loop { ... Element name = d.createElement(“name”) // set s to appropriate character string name.appendChild(createCDATASection(s)) emp.appendChild(name) ... } … }
Winter 2003 15
T h e n a m e s o f e m p lo y e e s a n d th e ir d e p a rt m e n t bui l d in g s
Winter 2003 16
nl1 = r1.getChildNodes() //r1 is root of doc for (int i1 = 1; i1 < n1.getLength; i1++) { nl2 = r2.getChildNodes() //r1 is root of doc for (int i2 = 1; i2 < n2.getLength; i2++)
… }
nl1 = r1.getChildNodes() //r1 is root of doc for (int i1 = 1; i1 < n1.getLength; i1++) { nl2 = r2.getChildNodes() //r1 is root of doc for (int i2 = 1; i2 < n2.getLength; i2++)
… }
is not the mos t e f f ic ie nt me thod
Why a query language? Extracting, Restructuring, Integration, Browsing…
XQuery http://www.w3.org/TR/xquery/ http://www.xml.com/pub/a/2002/10/16/xquery.html XPATH (part of a query language) http:www.w3.org/TR/xpath XSLT http://www.w3.org/TR/xslt http://www.mulberrytech.com/quickref/XSLTquickref.pdf and many others….
Winter 2003 20
… and, like other things in W3C, not necessarily the best.
Ingredients:
Winter 2003 21
that node to a variable For $x in document(“company.xml”)//department
Let $y := $x//employee
statement attempts to RETURN information
Winter 2003 22
Data on the Web’]: book with title subelement with value ‘Data on the Web’ -. //person[@id=1234’] : person with id attribute with value ‘1234’ -. //person/child[1]: first child subelement of personWinter 2003 25
OYXZR[\U ]^^%_Y`a!b!b bdcfeechggg!g%ijW OY]PkIZWmlPZ[\PR;Ono]PkpZ%W O-q%RZZrsWmlPZ[\PR-tTkuX!ZRPrU RsOnjq%RZZrvW O-PQQRvWxw-yZlPXz rU%{OnjPQQRTW O-PQQRvWG|U kIZ}~#! OnPQ Q%RvW OrZ{ W<fg%eb>! e bOnjrZ{ W OPWmTgebo;!e! eOPW OrZ{ W<fg%eb>! e g#OnjrZ{ W O-ZkIPz {WdU Rf k RU kIZ URqOnjZ!kIPz {W OnoXZ!R[\U ]W
OnjPQ Q%RTS!U!U VW
Winter 2003 26
> - % N %m ¡ ¢ -8 £
ª¬« ®¯°T±«² ³²´«μ ¶·°²%¸¹ º»´´-¬°±±¼ ½·¾ ¿jÀ¬ÁjÁ¯%°¬±d«² ¾°¸ ®°Y¬ÃÄ®¯°T±«²Ád°·x»³ ¾ ÅÆ °¬°^ ® ¯°^ ¬±d«²!Á²»·°-ÃYÇCÈ8»°±»TÉ f° ¸j¶s² (^) ¤ ¯%°v±«-² (^) ¨Ê© ®¯°T±«² ÁËÌ Ì8Í;Î (^) ©®°Î (^) ¤ Á¯°¬±d«² (^) ¨ Î
¤Á¥@¦§%¨
¤ ¯%°¬±d«²mË<ÌÌ8ÍÃYºÖÖÖ!×sØØ×ÙÙÙÙ¿^ ¨ ¤ °·»³^ ¾¨ ÚμËmªf«-v¶·¼Ûf«·°-¼^ «¬Ü^ ¤Ý^ °·»³^ ¾¨ ¤Á¯%°¬±d«²^ ¨ ¤Á¥@¦§%¨
Data Extraction
ÞßÐàáÒÓ âmã-Ó Ñáäã åÐæNçè ÔÔÐémÕ
ª¬« ®¯°¬±d«² ³²)´«μ ¶·°² ¸¹ º»´´T°±d± ¼½·#¾ ¿jÀ¬ÁjÁ¯%°v±«²-ês²»·°-ÃYÇCÈ8»°±d»TÉ ëì ®³´0¬ÃÄ® ¯%°v±«²ÁËÌ Ì8Í ¬° ¸j¶v² (^) ¤ ¯%°T±d«² (^) ¨E© ®³´Î ©®¯°T±d«²Á°·»³ ¾Î ¤ Á¯°T±«² (^) ¨ Î ¤Ýs¥¦§%¨
Winter 2003 27
P rint th e al l te l e p h one nu m b e rs lis te d f or C ae s ar:
¤0¥¦§%¨ © ª¬« ®¯°¬±d«² ³²)´«μ ¶·°² ¸¹ º»´´T°±d± ¼½·#¾ ¿jÀ¬ÁjÁ¯°T±«-²ês²»·°ÃYÇÛÈ8»%°±d»TÉ ë ¾°¸® ¸ÂTÃí®¯%° ¬±d«²Á\¸v°¾ ¬° ¸j¶v² (^) ¤ ¯%°T±d«² (^) ¨E© ®%¸Î (^) ¤Ý ¯%°v±«² (^) ¨ Î ¤Ýs¥¦§%¨ Ï 8ÐÑÒÓ ÔÕ ¤0¥¦§¨ ¤ ¯%°¬±d«²^ ¨ ¤ ¸v°¾^ ¨ ¹ÙØ8Ö!ÀMîïðØñ^ ò;Ö^ ¤Ý ¸v°¾^ ¨ ¤ ¸v°¾^ ¨ ¹ÙØ8Ö!ÀMîïðØñ^ òÙ^ ¤Ý ¸v°¾^ ¨ ¤Á¯%°¬±d«²^ ¨ ¤Á¥@¦§%¨
Winter 2003 28
P rint th e f irs t te l e p h one nu m b e r l is te d f or C ae s ar:
¤0¥¦§%¨ © ª¬« ®¯°¬±d«² ³²)´«μ ¶·°² ¸¹ º»´´T°±d± ¼½·#¾ ¿jÀ¬ÁjÁ¯°T±«-²ês²»·°ÃYÇÛÈ8»%°±d»TÉ ë ¾°¸ ®¸ÂTÃí®¯%° ¬±d«²Á\¸v°¾ ê\Ö ë ¬° ¸j¶v² (^) ¤ ¯%°T±d«² (^) ¨E© ®%¸Î (^) ¤Ý ¯%°v±«² (^) ¨ Î ¤Ýs¥¦§%¨ Ï 8ÐÑÒÓ ÔÕ ¤0¥¦§¨ ¤ ¯%°¬±d«²^ ¨ ¤ ¸v°¾^ ¨ ¹ÙØ8Ö!ÀMîïðØñ^ ò;Ö^ ¤Ý ¸v°¾^ ¨ ¤Á¯%°¬±d«²^ ¨ ¤Á¥@¦§%¨
Winter 2003 31
R e s u lt: ¤0¥¦§¨ ¤ μ³²°×vμ«²^ ¸v»μ¸^ ¨ ¤ÅÆ « ¨ È8»%°±d»@ój·¯°¬»¸v«-^ ¤ÁÅÆ « ¨ ¤ÅÆ °¬°^ ¨ÚμË)ª¬«s¶·¼C¬«·°-¼^ «fÜ^ ¤ÁÅÆ °f°^ ¨ ¤ ·«ö³^ ° ¨ ÷±o¸s°v³^ ½#»²´mÈ;¾^ °«8¯%»^ ¸j¬»^ ¤ Á·«ö³^ °¨ ¤ Áμ^ ³²°×Tμ«-²^ ¸v»μ¸^ ¨
¤ μ³²°×vμ«²^ ¸v»μ¸^ ¨ ¤ ÅÆ « ¨ ø j¼Ì¸jf»²Ü°¾^ «ö°^ ¤ ÁÅÆ « ¨ ¤ÅÆ °¬°^ ¨ ±o¸jT»²Ü°¾^ «ö˾^ «ö°-¼^ ¸Æ°-¼Cõ%«-·#õ^ ¤ ÁÅÆ °f°^ ¨ ¤ ·«ö³^ ° ¨ ø \¼Ì¸jT»²Ü^ °¾^ «ö°#«ù;«^ Å ó̸v«¯¯%°´F¼¼h¼^ ¤ Á·«ö³^ °¨ ¤ Áμ^ ³²°×Tμ«-²^ ¸v»μ¸^ ¨ ¼¼h¼ ¤
Data I nte g ration
Winter 2003 32
such as
function name (params) returns result”) are also included
Winter 2003 33