2012. 5. 10.TA. Min-Joong Lee([email protected], 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 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 #2Pa
ge 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 #2Pa
ge 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 #2Pa
ge 4
> java XPathQProcessor /phonebook/person[name=”Mary”]
-“[student ID]_SQL.txt” file including translated SQL queries.
CS360 Project #2Pa
ge 5
> java XPathQProcessor /phonebook/person[name=”Mary”]
select target from Edge where name=’phonebook’ and source=0select target from Edge where name=’person’ and source=1select target from Edge where name=’name’ and (source=2 or source=11)select target from Edge where (source=3 or source=12) and flag=1select vid from Value where (vid=4 or vid=13) and value=’Mary’select source from Edge where target=13select source from Edge where target=12select * from Edge where source=11select 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 #2Pa
ge 6
> java XPathQProcessor /phonebook/person[name=”Mary”]
<person><name>Mary</name><address>4713 Fruitdale Ave.</address><homephone>538-0922</homephone>
</person>
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 #2Pa
ge 7
XPath Specificationhttp://www.w3c.org/TR/xpath
CS360 Project #2Pa
ge 8
<phonebook><person> <name>Peter</name> <address>4711 Fruitdale
Ave.</address>
<officephone>533-9589</officephone>
<officephone>533-9590</officephone>
</person><person> <name>Mary</name> <address>4713 Fruitdale
Ave.</address>
<homephone>538-0922</homephone>
</person>
<phonebook>
An example document
Edge Labeled Tree structured XML document
Peter 538-0922
person person
name nameaddress
address
officephoneofficephone
homephone
Mary
533-9590533-9589
4711 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
Page
9CS360 Project #2
Edge
Peter
person person
name address officephoneofficephone
533-9590533-95894711 Fruitdale Ave.
phonebook00
1122
33 55 77 99
44 66 88 1010
source
target
name flag
0 1 phonebook 0
1 2 person 0
2 3 name 0
2 5 address 0
2 7 officephone 0
2 9 officephone 0
3 4 {null} 1
5 6 {null} 1
7 8 {null} 1
9 10 {null} 1
… … … …
Flag : 0 for reference type1 for string
Node order : left-deep traversal
◦ A separated value table Only contains leaf nodes Assume all value is string
vid value4 Peter
6 4711 Fruitdale Ave.
8 533-9589
10 533-9590
… …
Page 10CS360 Project #2
Value
Peter
personperson
name address officephoneofficephone
533-9590533-95894711 Fruitdale Ave.
phonebook00
11
22
33 55 77 99
4 6 8 10
vid value3 Peter
4 4711 Fruitdale Ave.
5 533-9589
6 533-9590
… …Pa
ge 11CS360 Project #2
Edge
Peter
person
person
name address officephoneofficephone
533-9590533-95894711 Fruitdale Ave.
phonebook00
1122
33 44 55 66
source
target
name flag
0 1 phonebook 0
1 2 person 0
2 3 name 0
2 4 address 0
2 5 officephone 0
2 6 officephone 0
… … … …
Node order : left-deep traversalFlag : Not use
Value
CS360 Project #2Pa
ge 12
/Company/Division/Division_name //Person[Name=“Tom”]/../Division_name
Page 13CS360 Project #2
XML Document
<Company> <Division>
<Division_name>Marketing</Division_name>
<Person> <Name> Tom </Name> <Age> 29 </Age> </person> <Person> <Name> Mary </Name> <Age> 35 </Age> </person> </Division></Company>
<Division_name>Marketing</Division_name>
/Company/Division/Person[Name=“Tom”]
Page 14CS360 Project #2
XML Document
<Company> <Division>
<Division_name>Marketing</Division_name>
<Person> <Name> Tom </Name> <Age> 29 </Age> </person> <Person> <Name> Mary </Name> <Age> 35 </Age> </person> </Division></Company>
<Person> <Name> Tom </Name> <Age> 29 </Age> </person>
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)◦ [email protected]
CS360 Project #2Pa
ge 15