Download presentation
Presentation is loading. Please wait.
1
2012. 5. 10. TA. Min-Joong Lee (mjlee@islab.kaist.ac.kr, x7837)
2
Implement an XML storing & querying system based on an RDBMS ◦ A program to store a given XML document into relations in an RDBMS Use MySQL 5.5.23 (and JDBC 5.1.20) Use DOM Parser Import org.w3c.dom.* and javax.xml.parsers.* ◦ A simple XPath query processor Cover a small part of the full XPath query functions CS360 Project #2 Pag e 2
3
Storing an XML document into relations in an RDBMS ◦ Input an XML document ◦ Database Name “XML_DB” ◦ Relational schema Edge (source, target, name, flag) Value(vid, value) Edge approach with a separated value table CS360 Project #2 Pag e 3 > java XMLToDB phonebook.xml
4
A simple XPath query processor ◦ Input An XPath query ◦ Output Translated SQL queries and the XML result -“[student ID]_SQL.txt” file including translated SQL queries. -“[student ID].txt“ file including the reconstructed XML result. CS360 Project #2 Pag e 4 > java XPathQProcessor /phonebook/person[name=”Mary”]
5
-“[student ID]_SQL.txt” file including translated SQL queries. CS360 Project #2 Pag e 5 > java XPathQProcessor /phonebook/person[name=”Mary”] select target from Edge where name=’phonebook’ and source=0 select target from Edge where name=’person’ and source=1 select target from Edge where name=’name’ and (source=2 or source=11) select target from Edge where (source=3 or source=12) and flag=1 select vid from Value where (vid=4 or vid=13) and value=’Mary’ select source from Edge where target=13 select source from Edge where target=12 select * from Edge where source=11 select value from Value where vid in (select target from Edge where source in (select target from Edge where source=11) )
6
-“[student ID].txt“ file including the reconstructed XML result. CS360 Project #2 Pag e 6 > java XPathQProcessor /phonebook/person[name=”Mary”] Mary 4713 Fruitdale Ave. 538-0922
7
A simple XPath query processor ◦ Restricted syntax No recursion, no attribute Covers only abbreviated syntaxes, and supports 1) Parent-child relationship, ‘/’ e.g. /phonebook/person/name 2) Ancestor-descendant relationship, ‘//’ e.g. //person/officephone 3) Child-parent relationship, ‘..’ e.g. //person[name=“Mary”]/../officephone 4) Exact matching, [=] e.g. /phonebook/person[name=“Peter”] CS360 Project #2 Pag e 7 XPath Specification http://www.w3c.org/TR/xpath
8
CS360 Project #2 Pag e 8 Peter 4711 Fruitdale Ave. 533-9589 533-9590 Mary 4713 Fruitdale Ave. 538-0922 An example document Edge Labeled Tree structured XML document Peter538-0922 person name address officephone homephone Mary533-9590533-95894711 Fruitdale Ave.4713 Fruitdale Ave. phonebook
9
◦ What is Edge Approach? Store all edges of the tree that represents an XML document in a single table Pag e 9 CS360 Project #2 Edge Peter person name address officephone 533-9590533-95894711 Fruitdale Ave. phonebook 0 0 1 1 2 2 3 3 5 5 7 7 9 9 4 4 6 6 8 8 10 sourcetargetnameflag 01phonebook0 12person0 23name0 25address0 27officephone0 29 0 34{null}1 56 1 78 1 910{null}1 ………… Flag : 0 for reference type 1 for string Node order : left-deep traversal
10
◦ A separated value table Only contains leaf nodes Assume all value is string vidvalue 4Peter 64711 Fruitdale Ave. 8533-9589 10533-9590 …… Pag e 10 CS360 Project #2 Value Peter person name address officephone 533-9590533-95894711 Fruitdale Ave. phonebook 0 0 1 1 2 2 3 3 5 5 7 7 9 9 4 6810
11
vidvalue 3Peter 44711 Fruitdale Ave. 5533-9589 6533-9590 …… Pag e 11 CS360 Project #2 Edge Peter person name address officephone 533-9590533-95894711 Fruitdale Ave. phonebook 0 0 1 1 2 2 3 3 4 4 5 5 6 6 sourcetargetnameflag 01phonebook0 12person0 23name0 24address0 25officephone0 26 0 ………… Node order : left-deep traversal Flag : Not use Value
12
CS360 Project #2 Pag e 12 … Import org.w3c.dom.* Import javax.xml.parsers.* … DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document doc = parser.parse(new File("example.xml")); NodeList children = doc.getChildNodes(); Node nextSibling = doc.getNextSibling();
13
/Company/Division/Division_name //Person[Name=“Tom”]/../Division_name Pag e 13 CS360 Project #2 XML Document Marketing Tom 29 Mary 35 Marketing
14
/Company/Division/Person[Name=“Tom”] Pag e 14 CS360 Project #2 XML Document Marketing Tom 29 Mary 35 Tom 29
15
Due date ◦ May 25th, 2012, 23:59:59 Midnight (20% penalty per day) Weight: 13% Send an e-mail to the TA with the attachment of Zip file containing Java source code, library, and README file ◦ Make the title of an e-mail as follows : [CS360 Project#2] Your Student ID, Your Name ◦ Make the title of Zip file corresponding to your student id: e.g., 20081234.zip TA’s email(for submission) ◦ mjlee@islab.kaist.ac.kr CS360 Project #2 Pag e 15
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.