XML Databases

2,491 views
2,267 views

Published on

Published in: Technology

XML Databases

  1. 1. XML and Databases Jussi Pohjolainen TAMK University of Applied Sciences
  2. 2. Similarities between XML and DB Database XML Storage XML-document DB model (relational) DTD and/or Schema Query Language (SQL) XQuery, XPath DB API (JDBC) DOM and SAX
  3. 3. Database Benefits <ul><li>XML &quot;environment&quot; lacks techniques that are built in into DBs: </li></ul><ul><ul><li>Indexing </li></ul></ul><ul><ul><li>Efficient storage </li></ul></ul><ul><ul><li>Support for multiple users </li></ul></ul><ul><ul><li>Transactions </li></ul></ul><ul><ul><li>Security </li></ul></ul><ul><ul><li>Locking </li></ul></ul>
  4. 4. Storing XML into DB <ul><li>XML-documents can be stored into DB </li></ul><ul><li>When storing xml into DB one must clarify the type of xml.. </li></ul><ul><li>XML-document types: </li></ul><ul><ul><li>Data centric </li></ul></ul><ul><ul><li>Document centric </li></ul></ul>
  5. 5. Data Centric vs. Document Centric? <ul><li>Data centric </li></ul><ul><ul><li>Usually generated by some system. </li></ul></ul><ul><ul><li>Server similar function to a database </li></ul></ul><ul><ul><li>Usually it does not matter in which order sibling-elements are. </li></ul></ul><ul><ul><li>Examples: books.xml </li></ul></ul><ul><li>Document centric </li></ul><ul><ul><li>Document focus </li></ul></ul><ul><ul><li>Does not have predictable structure </li></ul></ul><ul><ul><li>Usually the order of elements are crucial </li></ul></ul><ul><ul><li>Examples: xhtml </li></ul></ul>
  6. 6. DB Types <ul><li>Database can be </li></ul><ul><ul><li>XML-enabled DB </li></ul></ul><ul><ul><ul><li>Information in DB is NOT in XML </li></ul></ul></ul><ul><ul><ul><li>Requires a layer that converts XML to DB model </li></ul></ul></ul><ul><ul><ul><li>Problem: can lost information about the xml-document (order) </li></ul></ul></ul><ul><ul><ul><li>Use with Data Centric documents! </li></ul></ul></ul><ul><ul><li>Native XML </li></ul></ul><ul><ul><ul><li>XML is the fundamental unit of storage </li></ul></ul></ul><ul><ul><ul><li>Does not lose any information </li></ul></ul></ul><ul><ul><ul><li>Can be used with Data centric and Document centric documents! </li></ul></ul></ul>
  7. 7. Loss of Information? <ul><li>When using XML-enabled DBs, xml document is transformed from xml to db model. </li></ul><ul><li>When transforming, it is possible that some information will be lost. </li></ul><ul><ul><li>Order of sibling elements </li></ul></ul><ul><ul><li>Order of attributes </li></ul></ul><ul><li>But this does not matter, if the xml is data centric! </li></ul>
  8. 8. Designing XML – document for DB <ul><li>The use of elements? </li></ul><ul><ul><li><customer> </li></ul></ul><ul><ul><li><firstname>Homer</firstname> </li></ul></ul><ul><ul><li><lastname>Simpson</lastname> </li></ul></ul><ul><ul><li></customer> </li></ul></ul><ul><li>The use of attributes? </li></ul><ul><ul><li><customer firstname=&quot;Homer&quot; lastname=&quot;Simpson&quot;/ > </li></ul></ul>
  9. 9. Attribute vs. Element <ul><li>Readability </li></ul><ul><ul><li>matter of opinion </li></ul></ul><ul><li>Types </li></ul><ul><ul><li>Schema: just the same </li></ul></ul><ul><ul><li>DTD: with dtd you can define more detailed datatypes for attributes </li></ul></ul><ul><li>Programming </li></ul><ul><ul><li>DOM and SAX programming is easier if the xml uses attributes </li></ul></ul><ul><li>Document size </li></ul><ul><ul><li>When using attributes, the size of the xml – document is smaller </li></ul></ul><ul><li>Compatibility with DB </li></ul><ul><ul><li>When using attributes, xml document is closer to relational databases.. </li></ul></ul>
  10. 10. MySQL and XML <ul><li>Exporting xml – data </li></ul><ul><ul><li>mysqldump --xml databasename [tables] </li></ul></ul><ul><ul><li>http://dev.mysql.com/doc/refman/6.0/en/mysqldump.html </li></ul></ul><ul><li>Importing xml – data </li></ul><ul><ul><li>LOAD XML (Only with MYSQL 6) </li></ul></ul><ul><ul><li>http://dev.mysql.com/doc/refman/6.0/en/load-xml.html </li></ul></ul>
  11. 11. WEB SERVICE
  12. 12. Problem in the Internet Client B2C Website Partner Partner Partner xhtml e-mail phone e-mail
  13. 13. Solution Client B2C Website Partner Partner Partner xhtml xml xml xml
  14. 14. Web Service <ul><li>Web Service: a software system designed to support interoperable machine-to-machine interaction over a network </li></ul><ul><li>Communication system for different machines, platforms and programming languages </li></ul><ul><li>Service requester -> Service provider </li></ul>
  15. 15. XML? <ul><li>Web Service technology uses following XML – languages </li></ul><ul><ul><li>SOAP (Simple Object Access Protocol) </li></ul></ul><ul><ul><ul><li>SOAP is xml – language used when communicating with provider and requester </li></ul></ul></ul><ul><ul><li>WSDL (Web Service Description Language) </li></ul></ul><ul><ul><ul><li>WSDL is xml – language which is used to describe the service </li></ul></ul></ul>
  16. 16. SOAP Example: Request <ul><li><?xml version=&quot;1.0&quot;?> </li></ul><ul><li><soap:Envelope </li></ul><ul><li>xmlns:soap=&quot;http://www.w3.org/2001/12/soap-envelope&quot; </li></ul><ul><li>soap:encodingStyle=&quot;http://www.w3.org/2001/12/soap-encoding&quot;> </li></ul><ul><li><soap:Body xmlns:m=&quot;http://www.example.org/stock&quot;> </li></ul><ul><li><m:GetStockPrice> </li></ul><ul><li><m:StockName>IBM</m:StockName> </li></ul><ul><li></m:GetStockPrice> </li></ul><ul><li></soap:Body> </li></ul><ul><li></soap:Envelope> </li></ul>
  17. 17. SOAP Example: Response <ul><li><?xml version=&quot;1.0&quot;?> </li></ul><ul><li><soap:Envelope </li></ul><ul><li>xmlns:soap=&quot;http://www.w3.org/2001/12/soap-envelope&quot; </li></ul><ul><li>soap:encodingStyle=&quot;http://www.w3.org/2001/12/soap-encoding&quot;> </li></ul><ul><li><soap:Body xmlns:m=&quot;http://www.example.org/stock&quot;> </li></ul><ul><li><m:GetStockPriceResponse> </li></ul><ul><li><m:Price>34.5</m:Price> </li></ul><ul><li></m:GetStockPriceResponse> </li></ul><ul><li></soap:Body> </li></ul><ul><li></soap:Envelope> </li></ul>
  18. 18. THANK YOU!

×