XML and databases Chap. 12. Databases Today Data today: Structured - Info in databases – Data organized into chunks, similar entities groups together.

Slides:



Advertisements
Similar presentations
XML-XSL Introduction SHIJU RAJAN SHIJU RAJAN Outline Brief Overview Brief Overview What is XML? What is XML? Well Formed XML Well Formed XML Tag Name.
Advertisements

What is XML? a meta language that allows you to create and format your own document markups a method for putting structured data into a text file; these.
XML: Extensible Markup Language
1 XSLT – eXtensible Stylesheet Language Transformations Modified Slides from Dr. Sagiv.
XML: Extensible Markup Language. Slide Chapter Outline Introduction Structured, Semi structured, and Unstructured Data. XML Hierarchical (Tree)
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 13-1 COS 346 Day 25.
CS 898N – Advanced World Wide Web Technologies Lecture 21: XML Chin-Chih Chang
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide
1 COS 425: Database and Information Management Systems XML and information exchange.
4/17/2017.
XML –Query Languages, Extracting from Relational Databases ADVANCED DATABASES Khawaja Mohiuddin Assistant Professor Department of Computer Sciences Bahria.
XML Technologies and Applications Rajshekhar Sunderraman Department of Computer Science Georgia State University Atlanta, GA 30302
XML and ORACLE Rosa Isela López Aguilar Noviembre 2008.
September 15, 2003Houssam Haitof1 XSL Transformation Houssam Haitof.
Introducing XHTML: Module B: HTML to XHTML. Goals Understand how XHTML evolved as a language for Web delivery Understand the importance of DTDs Understand.
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.
Manohar – Why XML is Required Problem: We want to save the data and retrieve it further or to transfer over the network. This.
4/20/2017.
XML – Data Model, DTD and Schema
Sheet 1XML Technology in E-Commerce 2001Lecture 6 XML Technology in E-Commerce Lecture 6 XPointer, XSLT.
XML Anisha K J Jerrin Thomas. Outline  Introduction  Structure of an XML Page  Well-formed & Valid XML Documents  DTD – Elements, Attributes, Entities.
TDDD43 XML and RDF Slides based on slides by Lena Strömbäck and Fang Wei-Kleiner 1.
XSLT for Data Manipulation By: April Fleming. What We Will Cover The What, Why, When, and How of XSLT What tools you will need to get started A sample.
School of Computing and Management Sciences © Sheffield Hallam University To understand the Oracle XML notes you need to have an understanding of all these.
XP New Perspectives on XML Tutorial 6 1 TUTORIAL 6 XSLT Tutorial – Carey ISBN
Representing Web Data: XML CSI 3140 WWW Structures, Techniques and Standards.
XP 1 CREATING AN XML DOCUMENT. XP 2 INTRODUCING XML XML stands for Extensible Markup Language. A markup language specifies the structure and content of.
WORKING WITH XSLT AND XPATH
XML Overview. Chapter 8 © 2011 Pearson Education 2 Extensible Markup Language (XML) A text-based markup language (like HTML) A text-based markup language.
Chapter 26 XML and Internet Databases Copyright © 2004 Pearson Education, Inc.
XML 1 Enterprise Applications CE00465-M XML. 2 Enterprise Applications CE00465-M XML Overview Extensible Mark-up Language (XML) is a meta-language that.
XML과 Database 홍기형 성신여자대학교 성신여자대학교 홍기형.
1 CIS336 Website design, implementation and management (also Semester 2 of CIS219, CIS221 and IT226) Lecture 6 XSLT (Based on Møller and Schwartzbach,
 XML is designed to describe data and to focus on what data is. HTML is designed to display data and to focus on how data looks.  XML is created to structure,
Intro. to XML & XML DB Bun Yue Professor, CS/CIS UHCL.
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.
Processing of structured documents Spring 2002, Part 2 Helena Ahonen-Myka.
Lecture 22 XML querying. 2 Example 31.5 – XQuery FLWOR Expressions ‘=’ operator is a general comparison operator. XQuery also defines value comparison.
Avoid using attributes? Some of the problems using attributes: Attributes cannot contain multiple values (child elements can) Attributes are not easily.
CITA 330 Section 6 XSLT. Transforming XML Documents to XHTML Documents XSLT is an XML dialect which is declared under namespace "
XML and Web Services CS409 Application Services Even Semester 2007.
XSLT Kanda Runapongsa Dept. of Computer Engineering Khon Kaen University.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 27 XML: Extensible Markup Language.
1 Introduction  Extensible Markup Language (XML) –Uses tags to describe the structure of a document –Simplifies the process of sharing information –Extensible.
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.
XP 1 Creating an XML Document Developing an XML Document for the Jazz Warehouse XML Tutorial.
Copyright © 2004 Ramez Elmasri and Shamkant Navathe Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition Chapter 26-2 Introduction Although.
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.
An Introduction to XML Sandeep Bhattaram
XML Design Goals 1.XML must be easily usable over the Internet 2.XML must support a wide variety of applications 3.XML must be compatible with SGML 4.It.
The Semistructured-Data Model Programming Languages for XML Spring 2011 Instructor: Hassan Khosravi.
XML and Database.
COMP9321 Web Application Engineering Semester 2, 2015 Dr. Amin Beheshti Service Oriented Computing Group, CSE, UNSW Australia Week 4 1COMP9321, 15s2, Week.
Martin Kruliš by Martin Kruliš (v1.1)1.
XPath --XML Path Language Motivation of XPath Data Model and Data Types Node Types Location Steps Functions XPath 2.0 Additional Functionality and its.
C Copyright © 2011, Oracle and/or its affiliates. All rights reserved. Introduction to XML Standards.
Jackson, Web Technologies: A Computer Science Perspective, © 2007 Prentice-Hall, Inc. All rights reserved Chapter 7 Representing Web Data:
SEMI-STRUCTURED DATA (XML) 1. SEMI-STRUCTURED DATA ER, Relational, ODL data models are all based on schema Structure of data is rigid and known is advance.
XML Extensible Markup Language
XML Schema – XSLT Week 8 Web site:
XML Notes taken from w3schools. What is XML? XML stands for EXtensible Markup Language. XML was designed to store and transport data. XML was designed.
I Copyright © 2004, Oracle. All rights reserved. Introduction.
XML: Extensible Markup Language Abeiku Duncan Leslie Salami Anthony Mensah-Kumah Michelle Amarteifio Joseph Owusu-Badu.
CSE202 Database Management Systems
XML: Extensible Markup Language
Unit 4 Representing Web Data: XML
XML: Extensible Markup Language
XML in Web Technologies
Database Processing with XML
Chapter 7 Representing Web Data: XML
Presentation transcript:

XML and databases Chap. 12

Databases Today Data today: Structured - Info in databases – Data organized into chunks, similar entities groups together – Descriptions for entities in groups – same format, length, etc. Semi-structured – data has certain structure, but not all items identical – Schema info may be mixed in with data values – Similar entities grouped together – may have different attributes – Self-describing data – May be displayed as a graph Unstructured data – Data can be of any type, may have no format or sequence Web pages in HTML Video, sound, images

HTML

Why XML not HTML? HTML not suitable for specifying structured data from databases - – Does not contain schema information (unstructured only how to display information Want: Data source – database with Web interface Specify content and format of Web pages with HTML – Use HTML tags (predefined) for formatting Web documents

Types of XML documents 1.Data-centric – documents have small data items following a specific structure 2.Document-centric – documents with large amount of text (little structured data) 3.Hybrid – documents with structured and unstructured data

XML documents and DBMS Options: Use a DBMS to store XML documents as text – If DBMS has module for document processing Use DBMS to store XML document contents as data elements – Works if all documents have same structure – map XML schema to DB schema Design special DBMS for storing XML data – New type of XML DBMS designed, e.g. based on hierarchical model Create XML documents from preexisting RDBS and store into DB

XML XML – standard for structuring and exchanging data over Web Basic object is XML document Structuring concepts: – Elements (tags) – Attributes XML attributes – describe properties and characteristics of elements (tags) – Also Entities, identifiers, references

Elements Elements identified by: – Start tag – End tag Simple elements – data values Complex elements – constructed from other elements hierarchically – XML called a tree or hierarchical model – No limit on number of nesting elements

Well-formed XML document is well formed if: – Starts with XML declaration to indicate version and other relevant attributes – Single root element – Element matching pair of start/end tags within parent element – Syntactically correct – Can be processed to create internal tree

Semi-structured can be schemaless or have a schema

Semi-structured Schemaless If semistructured data – schemaless XML document Want to use info in XML document to determine schema of database To do this, parse document to create tree structure of data schemaless XML document is standalone (no corresponding file, specifying schema)

Slide

Whole document must be parsed beforehand to generate tree Each time access data, must parse document to create tree structure of data Parsing SLOWS down the process Set of API functions to manipulate tree and parsing models: – DOM (Document Object Model) - uses main memory to parse entire document – SAX – allows processing XML documents on the fly (also good for streaming XML documents) Semi-structured schemaless -- Parsing

Semi-structured not Schemaless To specify structure of data of semi-structured data if not schemaless – DTD (Document Type Definition), XML Schema Once parsed, allows validation of XML documents against: – DTD file or – XML schema file Valid means elements must follow structure and types specified in the separate schemas

XML DTD First specify root tag Parenthesis following element can be – Type – names of other elements (children) – (#PCDATA) means element is a leaf node (parsed character data – string) – | indicates either – * - element can be repeated 0 or more times – + - element can be repeated 1 or more times – ? – element can be repeated zero or one times – If no symbol, element must appear exactly once – Parenthesis can be nested Fig. 12.4

Slide

DTD cont’d To check for conformance to DTD add to XML document: Could also include DTD doc at beginning of XML doc Problems with DTD – datatypes not general – Special syntax requires specialized processors – Elements must follow ordering of document

XML Schema Alternative to (evolution from) DTD Standard for specifying structure of XML documents xsd – XML schema definition

XML Schema Same syntax rules, so same processors on both Could display the entire Company database as a single document Could store DB in XML format instead of relational DB Fig. 12.5

Slide

Slide

Slide

Features of XML Schema 1) To identify XML schema language elements used, specify a file at a Web site location Each such definition is XML namespace File name assigned to xsd, and this variable used as prefix to all XML schema commands

Features cont’d 2) Annotation, documents and language – Used for providing comments and other descriptions, e.g. “en” means english 3) Elements and types xsd:element - specifies element name xsd:ComplexType – if elements and children xsd:sequence –ordered set of element types, e.g. dept, employee, etc.,

Features cont’d 4) First-level elements specified in element tags 5)Element type, minimum and maximum occurrences MinOccurs, etc. 6)also xsd:key - PK xsd:unique tag, but must give constraint a name xsd:keyref – foreign keys

Features cont’d 7)Structures of complex elements - complex types 8)Composite (compound) attributes – complex types XSD 1.0 XSD 2.0 XSD 3.0 XSD 4.0

To Query XPointer – Specify position in XML document so other documents can link to it XPath – Query Language for selecting nodes from an XML document – Addresses parts of an XML document – Language mainly consists of location paths and expressions semantics for functionality – facilities for manipulation of strings, numbers and booleans

To Query: Use XPath (XML Path Language) to retrieve data XPath – expression language, based on tree representation of XML document Small query language Provides ability to navigate around the tree Addresses specific parts of XML document Provides a common syntax and shared model between XPointer and XSLT (Extensible Stylesheet Language Transformations)

XPath location path and expressions A location path is e.g. child::para[position=(1)] XPath expressions – Returns collection of element nodes that satisfy patterns specified in expression – Name with qualifier conditions – Separators: / means tag must appear as child of previous parent tag // means tag can appear as descendant of previous tag at any level

XPath To access whole XML document: Doc( /company/department //employee [employeeSalary gt 70000]/employeeName /company/employee [employeeSalary gt 70000]/employeeName /company/project/projectWorker [hours ge 20.0]

XPath Language Provide a common syntax and shared model between XPointer and XSLT – XSLT – functional language - no states, domain specific – XSLT - Language to create new document to transform the format of XML data into data of other formats (human readable) - eg. XML data into HTML, plain text, PDF – XSLT - Describes how files encoded in XML are to be formatted or transformed With XSLT can transform a document from XML to XML, from XML to HTML, etc. – Xpath is used to query elements

XSLT Language Uses Xpath to query elements (select= ) XSLT to specify results of the transformation (xsl: ) XSLT template:

XQuery No other query languages besides XPath and XSLT until XQuery – XQuery (like SQL) to query data using XPath expressions Based on SQL-like FLWOR for joins For, Let, Where, Orderby Return

XQuery – querying in XML For LET WHERE ORDER BY RETURN

FLWOR For, Let can appear any number of times or in any order Where, order by are optional Return – always needed Can be nested Can be argument to function (e.g. count, max())

XQUERY examples (Fig. 12.7) FOR $x IN doc( //employee [employeeSalary gt 70000]/employeeName RETURN $x/firstName, $x/lastName FOR $x IN doc( WHERE $x/employeeSalary gt RETURN $x/employeeName/firstName, $x/employeeName/lastName

XQUERY examples FOR $x IN doc( project[projectNumber=5]/projectWorker, $y IN doc( WHERE $x/hours gt 20.0 AND $y.ssn = $x.ssn RETURN $y/employeeName/firstName, $y/employeeName/lastName, $x/hours What does this do? What do you think of XQuery?

Another Example let $maxCredit := 3000 let $overdrawnCustomers := //customer[overdraft > $maxCredit] return count($overdrawnCustomers) for $v in //video for $a in //actor where $v/actorRef = order by $a, $v/year return concat($a, ":", $v/title)

SQL/XML How are the giants of the DB market incorporating XML? – Oracle is supporting SQL/XML (also IBM) These are extensions of SQL – SQL has a proprietary SQLXML for SQL Server Not the same as SQL/XML

SQL/XML XML Publishing Functions The XML Datatype Mapping Rules

XML Publishing Functions xmlelement()Creates an XML element, allowing the name to be specified. xmlattributes() Creates XML attributes from columns, using the name of each column as the name of the corresponding attribute. xmlroot()Creates the root node of an XML document. xmlcomment()Creates an XML comment. xmlpi()Creates an XML processing instruction. xmlparse()Parses a string as XML and returns the resulting XML structure. xmlforest() Creates XML elements from columns, using the name of each column as the name of the corresponding element. xmlconcat() Combines a list of individual XML values to create a single value containing an XML forest. xmlagg() Combines a collection of rows, each containing a single XML value, to create a single value containing an XML forest.

Another XML Example

SQL/XML I11 Jane I22 Niko I33 Mick

XML Datatype The XML Type also plays a second important role Relational databases now routinely store XML in individual columns The XML Type provides a standard type for such columns, which is useful both in SQL and in JDBC.

XML Datatype

SQL/XML Mapping Rules Mapping SQL character sets to Unicode. Mapping SQL s to XML Names. Mapping SQL data types (as used in SQL-schemas to define SQL-schema objects such as columns) to XML Schema data types. Mapping values of SQL data types to values of XML Schema data types. Mapping an SQL table to an XML document and an XML Schema document. Mapping an SQL schema to an XML document and an XML Schema document. Mapping an SQL catalog to an XML document and an XML Schema document. Mapping Unicode to SQL character sets. Mapping XML Names to SQL s.

XQuery vs. SQL/XML

Oracle XML DB Documentation for Oracle XML DB Documentation Some of the features are: – XML DB is not a separate server, but group of technologies – Can utilize unstructured/structured data – Features: XMLType DOM fidelity XML schema XPath search XML indexes – Can even generate XML from Oracle DB

Oracle XML Creating a Table of XMLType CREATE TABLE XMLTABLE OF XMLType; Creating a Table with an XMLType Column CREATE TABLE Example1 ( KEYVALUE varchar2(10) primary key, XMLCOLUMN xmltype ); existsNode() to find a Node to Match the XPath Expression extractValue() is the same as extract() except it returns value without the XML element tags, must be a single element

Oracle and XML Schema is created for XML when using SQL*Plus //A DTD is not needed, but you can register one, whereby XSD is a meta generic DTD (info)info Create table Company of XMLType; The rest of the definitiondefinition The same fields do not have to be specified in every element Use: set long 500 to show all values in table

SELECT extractValue(OBJECT_VALUE, '/Company/Employee/Fname') FNAME From Company

SELECT extractValue(OBJECT_VALUE, '/Company/Employee/Fname') FNAME FROM Company WHERE existsNode(OBJECT_VALUE, '/Company/Employee/Salary <"40000"') = 1;

Examples in this section are based on the following PurchaseOrder XML document: <PurchaseOrder xmlns:xsi=" xsi:noNamespaceSchemaLocation=" ADAMS PST SCOTT Julie P. Adams ADAMS R20 Julie P. Adams Redwood Shores, CA Ground

The Ruling Class Diabolique 8 1/2

existNode() existsNode() to find a Node to Match the XPath Expression Given this sample XML document, the following existsNode() operators return true (1). SELECT existsNode(value(X),'/PurchaseOrder/Reference') FROM XMLTABLE X; SELECT existsNode(value(X), '/PurchaseOrder[Reference="ADAMS PST"]') FROM XMLTABLE X;

extractValue() Example 3-7 Valid Uses of extractValue() SELECT extractValue(value(x),'/PurchaseOrder/Reference') FROM XMLTABLE X; Returns the following: EXTRACTVALUE(VALUE(X),'/PURCHASEORDER/REFERENCE') ADAMS PST

extractValue() Non-Valid Uses of extractValue() SELECT extractValue(value(X), '/PurchaseOrder/LineItems/LineItem/Description') FROM XMLTABLE X; -- FROM XMLTABLE X; -- * -- ERROR at line 3: -- ORA-19025: EXTRACTVALUE returns value of only one node

extract() Using extract() to Return an XML Fragment The following extract() statement returns an XMLType that contains an XML document fragment containing occurrences of the Description node. These match the specified XPath expression shown. Note: In this case the XML is not well formed as it contains more than one root node. set long SELECT extract(value(X), '/PurchaseOrder/LineItems/LineItem/Description') FROM XMLTABLE X; -- This returns: -- EXTRACT(VALUE(X),'/PURCHASEORDER/LINEITEMS/LINEITEM/DESCRIPTION') The Ruling Class Diabolique 8 1/2

updateXML() Using updateXML() to Update a Text Node Value Identified by an XPath Expression This example uses updateXML() to update the value of the text node identified by the XPath expression `/PurchaseOrder/Reference': UPDATE XMLTABLE t SET value(t) = updateXML(value(t), '/PurchaseOrder/Reference/text()', 'MILLER PST') WHERE existsNode(value(t), '/PurchaseOrder[Reference="ADAMS PST"]') = 1; This returns: 1 row updated.

Oracle XML Oracle XML DB complies with the W3C XSL/XSLT recommendation by supporting XSLT transformations in the database. In Oracle XML DB, XSLT transformations can be performed using either of the following: – XMLTransform() function – XMLType datatype's transform() method

transform() Using transform() to Transform an XSL The following example shows how transform() can apply XSLT to an XSL stylesheet, PurchaseOrder.xsl, to transform the PurchaseOrder.xml document: SELECT value(t).transform(xmltype(getDocument('purchaseOrder.xsl'))) from XMLTABLE t where existsNode(value(t), '/PurchaseOrder[Reference="MILLER PST"]' ) = 1; This returns: VALUE(T).TRANSFORM(XMLTYPE(GETDOCUMENT('PURCHASEORDER.XSL'))) Since the transformed document using XSLT is expected as an instance of XMLType, the source could easily be a database table.

Research Topics XML to relational data mapping Updating XML in RDBMS XML and access control XML Parsing – reference on this topic: A Brief History of XML