XML and Databases.

Slides:



Advertisements
Similar presentations
CSCI N241: Fundamentals of Web Design Copyright ©2004 Department of Computer & Information Science Introducing XHTML: Module B: HTML to XHTML.
Advertisements

Chapter 23: XML.
History Leading to XHTML
CS 898N – Advanced World Wide Web Technologies Lecture 21: XML Chin-Chih Chang
Semi-structured Data. Facts about the Web Growing fast Popular Semi-structured data –Data is presented for ‘human’-processing –Data is often ‘self-describing’
©Silberschatz, Korth and Sudarshan3.1Database System Concepts - 6 th Edition SQL Schema Changes and table updates instructor teaches.
1 Advanced Topics XML and Databases. 2 XML u Overview u Structure of XML Data –XML Document Type Definition DTD –Namespaces –XML Schema u Query and Transformation.
XML Databases and introducing their languages, XQuery, XSLT, and XPath
4/20/2017.
XML Anisha K J Jerrin Thomas. Outline  Introduction  Structure of an XML Page  Well-formed & Valid XML Documents  DTD – Elements, Attributes, Entities.
Why XML ? Problems with HTML HTML design - HTML is intended for presentation of information as Web pages. - HTML contains a fixed set of markup tags. This.
©Silberschatz, Korth and Sudarshan10.1Database System ConceptsIntroduction XML: Extensible Markup Language Defined by the WWW Consortium (W3C) Originally.
XML By Dr.S.Sridhar, Ph.D.(JNUD), RACI(Paris, NICE), RMR(USA), RZFM(Germany) DIRECTOR ARUNAI ENGINEERING COLLEGE TIRUVANNAMALAI.
Chapter 10: XML.
Maziar Sanaii Ashtiani – SCT – EMU, Fall 2011/12.
Computing & Information Sciences Kansas State University Friday, 17 Oct 2007CIS 560: Database System Concepts Lecture 21 of 42 Friday, 17 October 2008.
XML - DTD. The building blocks of XML documents Elements, Tags, Attributes, Entities, PCDATA, and CDATA.
1 © Netskills Quality Internet Training, University of Newcastle Introducing XML © Netskills, Quality Internet Training University.
XML 1 Enterprise Applications CE00465-M XML. 2 Enterprise Applications CE00465-M XML Overview Extensible Mark-up Language (XML) is a meta-language that.
XMLI Structure of XML Data Structure of XML Data XML Document Schema XML Document Schema XPATH XPATH.
XHTML. Introduction to XHTML What Is XHTML? – XHTML stands for EXtensible HyperText Markup Language – XHTML is almost identical to HTML 4.01 – XHTML is.
These Questions are copied from
FIGIS’ML Hands-on training - © FAO/FIGIS An introduction to XML Objectives : –what is XML? –XML and HTML –XML documents structure well-formedness.
Chapter 27 The World Wide Web and XML. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.27-2 Topics in this Chapter The Web and the Internet.
XML. 2 XML- Some Links XML Tutorials – Some Links me=htmlhttp://
XML A web enabled data description language 4/22/2001 By Mark Lawson & Edward Ryan L’Herault.
1 Chapter 10: XML What is XML What is XML Basic Components of XML Basic Components of XML XPath XPath XQuery XQuery.
Computing & Information Sciences Kansas State University Thursday, 15 Mar 2007CIS 560: Database System Concepts Lecture 24 of 42 Thursday, 15 March 2007.
Introduction to XML This presentation covers introductory features of XML. What XML is and what it is not? What does it do? Put different related technologies.
XML Instructor: Charles Moen CSCI/CINF XML  Extensible Markup Language  A set of rules that allow you to create your own markup language  Designed.
XML Name: Niki Sardjono Class: CS 157A Instructor : Prof. S. M. Lee.
Chapter 27 The World Wide Web and XML. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.27-2 Topics in this Chapter The Web and the Internet.
XML Introduction. What is XML? XML stands for eXtensible Markup Language XML stands for eXtensible Markup Language XML is a markup language much like.
The eXtensible Markup Language (XML). Presentation Outline Part 1: The basics of creating an XML document Part 2: Developing constraints for a well formed.
Chapter 23 XML. 2 Introduction  XML: eXtensible Markup Language (What is a Markup language?)  Defined by the WWW Consortium (W3C)  Originally intended.
XML Introduction. Markup Language A markup language must specify What markup is allowed What markup is required How markup is to be distinguished from.
Jennifer Widom XML Data Introduction, Well-formed XML.
CS 157B: Database Management Systems II February 11 Class Meeting Department of Computer Science San Jose State University Spring 2013 Instructor: Ron.
XML e X tensible M arkup L anguage (XML) By: Albert Beng Kiat Tan Ayzer Mungan Edwin Hendriadi.
COMP9321 Web Application Engineering Semester 2, 2015 Dr. Amin Beheshti Service Oriented Computing Group, CSE, UNSW Australia Week 4 1COMP9321, 15s2, Week.
What is XML? eXtensible Markup Language eXtensible Markup Language A subset of SGML (Standard Generalized Markup Language) A subset of SGML (Standard Generalized.
Representing data with XML SE-2030 Dr. Mark L. Hornick 1.
Introduction to XML XML – Extensible Markup Language.
ADT 2010 Introduction to XML, XPath (& XQuery) Chapter 10 in Silberschatz, Korth, Sudarshan “Database System Concepts” Stefan Manegold
Computing & Information Sciences Kansas State University Friday, 20 Oct 2006CIS 560: Database System Concepts Lecture 24 of 42 Friday, 20 October 2006.
Introduction to DTD A Document Type Definition (DTD) defines the legal building blocks of an XML document. It defines the document structure with a list.
Chapter 8: XML. 2 XML Structure of XML Data XML Document Schema Querying and Transformation Application Program Interfaces to XML Storage of XML Data.
Advanced Java Session 5 New York University School of Continuing and Professional Studies.
CITA 330 Section 2 DTD. Defining XML Dialects “Well-formedness” is the minimal requirement for an XML document; all XML parsers can check it Any useful.
XML Databases Presented By: Pardeep MT15042 Anurag Goel MT15006.
Extensible Markup Language (XML) Pat Morin COMP 2405.
CS 480: Database Systems Lecture 26 March 18, 2013.
XML intro. What is XML? XML stands for EXtensible Markup Language XML is a markup language much like HTML XML was designed to carry data, not to display.
XML BASICS and more…. What is XML? In common:  XML is a standard, simple, self-describing way of encoding both text and data so that content can be processed.
XML to Relational Database Mapping
Unit 4 Representing Web Data: XML
CS 480: Database Systems Lecture 25 March 15, 2013.
Querying and Transforming XML Data
XML By Dr.S.Sridhar, Ph.D.(JNUD), RACI(Paris, NICE), RMR(USA), RZFM(Germany)
XML QUESTIONS AND ANSWERS
Chapter 23: XML Database System concepts,6th Ed.
CS 480: Database Systems Lecture 28 March 22, 2013.
Introduction to XHTML.
XML in Web Technologies
Database Processing with XML
Chapter 7 Representing Web Data: XML
XML Data Introduction, Well-formed XML.
eXtensible Markup Language (XML)
CSE591: Data Mining by H. Liu
Siddhesh Bhobe Persistent eBusiness Solutions
Presentation transcript:

XML and Databases

Introduction XML: Extensible Markup Language Defined by the WWW Consortium (W3C) Derived from SGML (Standard Generalized Markup Language), but simpler to use than SGML Documents have tags giving extra information about sections of the document E.g. <title> XML </title> <slide> Introduction …</slide> Extensible, unlike HTML Users can add new tags, and separately specify how the tag should be handled for display

XML Introduction (Cont.) The ability to specify new tags, and to create nested tag structures make XML a great way to exchange data, not just documents. Much of the use of XML has been in data exchange applications, not as a replacement for HTML Tags make data (relatively) self-documenting E.g. <university> <department> <dept_name> Comp. Sci. </dept_name> <building> Taylor </building> <budget> 100000 </budget> </department> <course> <course_id> CS-101 </course_id> <title> Intro. to Computer Science </title> <dept_name> Comp. Sci </dept_name> <credits> 4 </credits> </course> </university>

Structure of XML Data Tag: label for a section of data Element: section of data beginning with <tagname> and ending with matching </tagname> Elements must be properly nested Proper nesting <course> … <title> …. </title> </course> Improper nesting <course> … <title> …. </course> </title> Formally: every start tag must have a unique matching end tag, that is in the context of the same parent element. Every document must have a single top-level element

Attributes Elements can have attributes <course course_id= “CS-101”> <title> Intro. to Computer Science</title> <dept name> Comp. Sci. </dept name> <credits> 4 </credits> </course> Attributes are specified by name=value pairs inside the starting tag of an element An element may have several attributes, but each attribute name can only occur once <course course_id = “CS-101” credits=“4”>

XML Document Schema Database schemas constrain what information can be stored, and the data types of stored values XML documents are not required to have an associated schema However, schemas are very important for XML data exchange Otherwise, a site cannot automatically interpret data received from another site Two mechanisms for specifying XML schema Document Type Definition (DTD) Widely used XML Schema Newer, increasing use

Document Type Definition (DTD) The type of an XML document can be specified using a DTD DTD constraints structure of XML data What elements can occur What attributes can/must an element have What subelements can/must occur inside each element, and how many times. DTD does not constrain data types All values represented as strings in XML DTD syntax <!ELEMENT element (subelements-specification) > <!ATTLIST element (attributes) >

University DTD <!DOCTYPE university [ <!ELEMENT university ( (department|course|instructor|teaches)+)> <!ELEMENT department ( dept name, building, budget)> <!ELEMENT course ( course id, title, dept name, credits)> <!ELEMENT instructor (IID, name, dept name, salary)> <!ELEMENT teaches (IID, course id)> <!ELEMENT dept name( #PCDATA )> <!ELEMENT building( #PCDATA )> <!ELEMENT budget( #PCDATA )> <!ELEMENT course id ( #PCDATA )> <!ELEMENT title ( #PCDATA )> <!ELEMENT credits( #PCDATA )> <!ELEMENT IID( #PCDATA )> <!ELEMENT name( #PCDATA )> <!ELEMENT salary( #PCDATA )> ]>

Steps Mapping XML into relational data Generating XML using Java and JDBC Storing XML XML on the Web XML support in Oracle XML API for databases Conclusion

Mapping XML into relational data

The database We can model the database with a document node and its associated element node: <?xml version=“1.0” ?> <myDatabase> table1 table2 ... tablen </myDatabase> Order of tables is immaterial

The table Each table of the database is represented by an element node with the records as its children: <customer> record1 record2 ... recordm </customer> Again, order of the records is immaterial, since the relational data model defines no ordering on them.

The record A record is also represented by an element node, with its fields as children: <custRec> field1 field2 ... fieldm </custRec> The name is arbitrary, since the relational data model doesn't define a name for a record type

The field A field is represented as an element node with a data node as its only child: <custName type="t"> d </custName> If d is omitted, it means the value of the fields is the empty string. The value of t indicates the type of the value

Example <?xml version=“1.0” ?> <myDatabase> <customers> <custRec> <custName type=“String”>Robert Roberts</custName> <custAge type=“Integer”>25</custAge> </custRec> <custName type=“String”>John Doe</custName> <custAge type=“Integer”>32</custAge> </customers> </myDatabase>

Generating XML using Java and JDBC

Generating XML from relational data Step 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 = “<?xml version=‘1.0’?><myDatabase><customers>”; while (rs.next()) { xml.append(“<custRec><custName>”); xml.append(rs.getString(“Name”)); xml.append(“</custName><custAge>”); xml.append(rs.getInt(“Age”)); xml.append(“</custAge></custRec>”); } xml.append(“</customers></myDatabase>”);

Storing XML

Storing XML in relational tables Step 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

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

XML in IE 5.0

insert the XSL… <?xml version=“1.0” ?> <?xml-stylesheet type="text/xsl" href="http://myServer/Customer.xsl"?> <myDatabase> <customers> <custRec> <custName type=“String”>Robert Roberts</custName> <custAge type=“Integer”>25</custAge> </custRec> … other records here … </customers> </myDatabase>

XML with XSL in IE 5.0

XML API with database