TA. Min-Joong Lee x7837)
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 (and JDBC ) 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
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
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”]
-“[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) )
-“[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
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
CS360 Project #2 Pag e 8 Peter 4711 Fruitdale Ave Mary 4713 Fruitdale Ave An example document Edge Labeled Tree structured XML document Peter person name address officephone homephone Mary Fruitdale Ave.4713 Fruitdale Ave. phonebook
◦ 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 Fruitdale Ave. phonebook sourcetargetnameflag 01phonebook0 12person0 23name0 25address0 27officephone {null} {null}1 ………… Flag : 0 for reference type 1 for string Node order : left-deep traversal
◦ A separated value table Only contains leaf nodes Assume all value is string vidvalue 4Peter Fruitdale Ave …… Pag e 10 CS360 Project #2 Value Peter person name address officephone Fruitdale Ave. phonebook
vidvalue 3Peter Fruitdale Ave …… Pag e 11 CS360 Project #2 Edge Peter person name address officephone Fruitdale Ave. phonebook sourcetargetnameflag 01phonebook0 12person0 23name0 24address0 25officephone ………… Node order : left-deep traversal Flag : Not use Value
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();
/Company/Division/Division_name //Person[Name=“Tom”]/../Division_name Pag e 13 CS360 Project #2 XML Document Marketing Tom 29 Mary 35 Marketing
/Company/Division/Person[Name=“Tom”] Pag e 14 CS360 Project #2 XML Document Marketing Tom 29 Mary 35 Tom 29
Due date ◦ May 25th, 2012, 23:59:59 Midnight (20% penalty per day) Weight: 13% Send an to the TA with the attachment of Zip file containing Java source code, library, and README file ◦ Make the title of an as follows : [CS360 Project#2] Your Student ID, Your Name ◦ Make the title of Zip file corresponding to your student id: e.g., zip TA’s (for submission) ◦ CS360 Project #2 Pag e 15