Top Banner

of 51

XML Database

Oct 15, 2015

Download

Documents

dnguyenbinh
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
  • **XML v c s d liu

  • **Ni dungM uS ging nhau v khc nhau gia c s d liu v XMLLoi c s d liu XMLTr d liu XML trong RDBMSMinh ha

  • Tm quan trng ca XMLExtensible Markup Language (XML) l chun chnh biu din thng tin trn Internet ang c s pht trin rt nhanh Hu ht cc t chc u dng XML lm chun chia s thng tin.Tt c cc framework pht trin D hin nay u h tr XML(.NET, Java).Tt c cc kin trc h thng WEB hin i c thit k da trn XML.

  • ng dng ca XML

    Lu tr d liu

    Trao i d liu

    Hin th d liu

    Tt c u lin quan n d liu

  • ng dng ca XML

    Data Storage

    Lu tr thun ty dng file XMLLu tr XML trong CSDL quan hLu tr trong XML-enabled databases

  • ng dng ca XML

    Data Interchange

    Khng cn s dng cc middleware nu ng dng c th c ghi trc tip XML.

    Trn 80% d liu trao i trn mng hin nay di dng XML (per Gartner Group)

  • ng dng ca XML

    Hin th d liuCng mt ngun thng tin c hin th trn nhiu loi thit b khc nhau.Trc khi c XML . . .Phn ln dng HTMLHoc hoc 1 tp cc trang phc v cho cc thit b khc nhau.

  • ng dng ca XML

    Sau khi c XMLLu tr d liu di dng XML documentsV 1 XSL document cho 1 loi thit b.

    Nu xut hin loi thit b mi ch cnPht trin protocol mi (e.g., WAP)Pht trin 1 XSL document mi

  • ng dng ca XML

    Sau c thChuyn c XML v XSL xung client.

    HocChuyn i XML v XSL ti serverChuyn ni dung markup ph hp xung client.

  • **Qun l d liu vi qun l t liuQun l d liu:Cn c s d liu cho tr d liuRelational hay Object databaseQun l t liuCn h thng qun l ni dungH thng qun l ni dung c th c xy dng trn c s d liu

  • Lu tr v Truy vn d liu vi XML D liu XML c th c lu tr bng cc cch sau:Di dng h thng tp tinC s d liu quan hC s d liu XML

  • Lu tr d liu XML di dng tp tinLu tr x dng trc tip tp tin XML khi:D liu c truy cp bi nhiu h thng khc nhauD liu c th bcTp d liu nhTc truy cp khng quan trngCh thc hin cc truy vn n ginCc kiu d liu khng quan trng

  • Why XML for databases? Mt trong nhng nguyn nhn chnh s dng XML l n h tr vic trao i d liu bn cu trc gia cc ng dng qua mi trng Iternet. Vic s dng CSDL lu tr vn bn XML s gip cho ngi dng truy cp thng tin tt hn. XML rt mm do D liu lu tr di dng XML c th d dng thay i cng vi s tin ha ca cc dch v ca h thng.

  • C 2 loi chnh:

    XML-enabled. nh x vn bn XML thnh d liu lu tr trong CSDL.

    Native XML (NXD) M hnh lu tr bn trong CSDL c xy dng da trn XMLv s dng vn bn XML nh l n v lu tr c bn.XML Database l g?n gin l CSDL h tr lu tr vn bn XML

  • XML khng ph hp khiLung d liu x l di dng quan hTc x l l rt quan trngThnh phn d liu lu tr nm ngoi cc kiu d liu m XML c th th hinc bit l cc d liu c bn cht dng bng.

  • XML ph hp khiSchema d b thay iD liu c quan h th bcPhn t d liu c cu trc r rng v c nh

  • **S ging nhau vi c s d liuLuTr: Table vi ti liu XMLLc : Lc c s d liu vi DTD, ngn ng lc XMLNgn ng Query: SQL vi XQL, XML-QL, QUILTGiao din lp trnh: JDBC vi SAX, DOM

  • **Khc nhau vi c s d liuStorge mechanismIndexingBuilt-in securityTransaction supportData integrityMulti-user accessQuery across multiple data sources

  • A Native XML Databasenh ngha m hnh vt l lu tr vn bn XML v lu tr rt trch thng tin t m hnh .Minimum model = elements, attributes, PCDATA, and document orderXPath data model, XML Infoset, DOM, SAX, n v lu tr c bn l vn bn XMLC th c xy dng da trn cc CSDLhin c: relational/hierarchical/object-oriented database, indexed compressed files,

  • Phn Lai NXDDocument-based storageLu ton b vn bn di dng text hoc nh phn Cung cp cng c truy xut vn bn XMLV d: lu vn bn XML nh l 1 BLOB trong 1 relational database, file in a file system + XML-aware indexesThun li:Better round tripping levelFast reconstruction of the whole documentNode-based storage Lu tr cc nt trong vn bn ring lV d: to map the DOM to relational tables such as Elements, Attributes, Entities

  • XML-Enabled Databases vs NXDNative XML databases C th bo ton cu trc vn bn XMLV l thuyt th XML-enabled c th thc hin iu ny nhng thc t th khngC th lu tr vn bn XML m khng cn schema hoc DTDCh cung cp cc XML APIs truy cp d liu nh XPath, DOM, XML-enabled h tr truy cp trc tip d liu.

  • Current Native XML DatabasesDanh sch sn phm:http://www.rpbourret.com/xml/ProdsNative.htmV d:Oracle Berkeley DB XMLTIMBER Natix, eXist, Lore, Tamino, dbXML,

  • **XML enabled databaseProsCung cp k thut c s d liuConsS chuyn i gia XML v c s d liu c cn: Chuyn i thc thi han tonThng tin cu trc XML phc tp rt kh chuyn i sang tables

  • Lu tr XML trong CSDL quan hXML/relational mapping l qu trnh chuyn i gia m hnh quan h v XMLVn bn XML c th chuyn thnh m hnh quan h v ngc li.C nhiu cch thc khc nhau thc hin vic chuyn i ny.

  • Relational Model Order of rows is not guaranteed unless the ORDER clause is used in one or more columns Relations (tables) Data is represented in n-ary relations. Has a domain that represents a set of values Attributes (columns) Strict schema Restrictive The strict schema insures data integrity

  • XML Model The XML Model is hierarchical format Data is represented in trees structuresThere's nodesRelationships between the nodeThe schema provides flexibilityEasily modified format

  • multiple elements represented in a hierarchy, including a rootComments element and one or more individual Comment elements pertaining to a given item.

  • XML Model VS. Relational Model? XML data is hierarchical

    XML data is self-describing

    XML data has inherent ordering

    An XML database contains collections relational data is represented in a model of logical relationships.

    relational data is not self-describing.

    Relational data does not have inherent ordering.

    A relational database contains tables

  • XML vs. Relational Database

    ABC 30 XYZ 40

    CUSTOMERNameAgeABC30XYZ40

  • XML vs. Relational Database

  • XML vs. Relational Database

  • XML documents can be decomposed into a relational table. Those decomposed XML documents can be made into relational tables and published to an XML document( they might differ from the original) During the decomposing process, the XML document loses most of it structure in order to map into the relational table; not all the tags are stored in the relational tables.Going from XML Model to Relational Model

  • XML-to-Relational mappingSchema mappingDatabase schema c to ra t XML schema hoc DTD lu tr vn bn XML.Data mappingChia nh vn bn XML thnh cc relational tuples v chn vo CSDL quan h.

  • Inlined DTD graph

  • Generated Database Schema

  • Data MappingXML file is used to insert data into generated database schemaParser is used to fetch data from XML file.

  • 94872PEN19.9530 94866BINDER7.9526 92219LABELS12.95250

    Example of an XML documentXML document decomposed into a relation Items Order

  • Another Example.....

    2003-07-28456XY-471416.80

    B-98762.34

    Sales OrderItems table

  • Example

    Robert Roberts 25 John Doe 32

  • Generating XML from relational dataStep 1 : Set up the database connection // Create an instance of the JDBC driver so that it has// a chance to register itself Class.forName(sun.jdbc.odbc.JdbcOdbcDriver).newInstance();

    // Create a new database connection. Connection con = DriverManager.getConnection(jdbc:odbc:myData, , );

    // Create a statement object that we can execute queries with Statement stmt = con.createStatement();

  • Generating XML (cont.)Step 2 : Execute the JDBC query

    String query = Select Name, Age from Customers;ResultSet rs = stmt.executeQuery(query);

  • Generating XML (cont.)Step 3 : Create the XML!

    StringBuffer xml = ;

    while (rs.next()) {xml.append(); xml.append(rs.getString(Name)); xml.append(); xml.append(rs.getInt(Age));xml.append();}xml.append();

  • Storing XML in relational tablesStep 1 : Set up the parser

    StringReader stringReader = new StringReader(xmlString);InputSource inputSource = new InputSource(stringReader); DOMParser domParser = new DOMParser();domParser.parse(inputSource);Document document = domParser.getDocument();

  • Storing XML (cont.)Step 2 : Read values from parsed XML document

    NodeList nameList = doc.getElementsByTagName(custName);NodeList ageList = doc.getElementsByTagName(custAge);

  • Storing XML (cont.)Step 3 : Set up database connection

    Class.forName(sun.jdbc.odbc.JdbcOdbcDriver).newInstance();Connection con = DriverManager.getConnection(jdbc:odbc:myDataBase, , );Statement stmt = con.createStatement();

  • Storing XML (cont.)Step 4 : Insert data using appropriate JDBC update query

    String sql = INSERT INTO Customers (Name, Age) VALUES (?,?);PreparedStatement pstmt = conn.prepareStatement(sql);int size = nameList.getLength();for (int i = 0; i < size; i++) { pstmt. setString(1, nameList.item(i).getFirstChild().getNodeValue()); pstmt.setInt(2, ageList.item(i).getFirstChild().getNodeValue()); pstmt.executeUpdate(sql);}

  • XML on the Web (Servlets) public void doGet(HttpServletRequest req, HttpServletResponse resp) { resp.setContentType("text/xml"); PrintWriter out = new PrintWriter(resp.getOutputStream()); generate XML here, as before out.println(xmlGenerated); out.flush(); out.close();}

    Appropriate XSL can be inserted for display

  • Lets insert the XSL

    Robert Roberts 25 other records here

  • XML with XSL in IE 5.0

  • Interface SQLXMLJDBC 4.oL i tng h tr lu trgi tr XML nh l 1 ct trong bngSQLXML interface cung cp cc phng thc truy cp XML value nh l String, a Reader hoc Writer,hoc Stream. XML value cng c th truy cp thng qua1 Source hoc Result, m c s dng bi cc XML Parser API nh DOM, SAX, XSLT transforms v XPath

  • S dng XMLSQL iterface

    ******Not just the internet but different applications, platforms, and so on.A database that stores XML documents. There are two types. The first is the "XML-enabled database," which is a relational or object-oriented database that has been extended to hold XML data. In this method, there is always a conversion to and from the XML document to the underlying structure such as rows and columns in the relational model. In addition, the XML-enabled database may only store part of the XML document.

    The second is the "native XML database," which indexes XML documents directly and stores the entire XML document and related elements. Depending on the application, the native XML database may provide better performance than the XML-enabled database. For more information on XML databasesAs we have already learned about the relational data model we know that it is made up of relations (tables), attributes (columns)

    A relational record is an unordered list of named values An XML document is a tree of nodes