Querying and Transforming XML Data

Slides:



Advertisements
Similar presentations
XML Examples. Bank Information Basic structure: A-101 Downtown 500 … Johnson Alma Surrey … A-101 Johnson …
Advertisements

XML: Extensible Markup Language
XPath Eugenia Fernandez IUPUI. XML Path Language (XPath) a data model for representing an XML document as an abstract node tree a mechanism for addressing.
Chapter 10: XML. ©Silberschatz, Korth and Sudarshan10.2Database System ConceptsIntroduction XML: Extensible Markup Language Defined by the WWW Consortium.
Database System Concepts ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 10: XML.
XSL Concepts Lecture 7. XML Display Options What can XSL Transformations do? generation of constant text suppression of content moving text (e.g., exchanging.
1 COS 425: Database and Information Management Systems XML and information exchange.
L13-S1 XML 2003 SJSU -- CmpE Database Design Dr. M.E. Fayad, Professor Computer Engineering Department, Room #283I College of Engineering San José State.
XML –Query Languages, Extracting from Relational Databases ADVANCED DATABASES Khawaja Mohiuddin Assistant Professor Department of Computer Sciences Bahria.
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.
Overview of XPath Author: Dan McCreary Date: October, 2008 Version: 0.2 with TEI Examples M D.
Introduction to XPath Bun Yue Professor, CS/CIS UHCL.
SD2520 Databases using XML and JQuery
XMLII XSchema XSchema XQuery XQuery. XML Schema XML Schema is a more sophisticated schema language which addresses the drawbacks of DTDs. Supports XML.
XML Query Languages Notes Based on Chapter 10 of Database System Concepts.
XMLII XSchema XSchema XQuery XQuery Oracle XSU Oracle XSU.
Navigating XML. Overview  Xpath is a non-xml syntax to be used with XSLT and Xpointer. Its purpose according to the W3.org is  to address parts of an.
Chapter 10: XML. ©Silberschatz, Korth and Sudarshan10.2Database System ConceptsIntroduction XML: Extensible Markup Language Defined by the WWW Consortium.
Lecture 7 of Advanced Databases XML Querying & Transformation Instructor: Mr.Ahmed Al Astal.
 Structure of XML Data  XML Document Schema  Querying and Transformation  Application Program Interfaces to XML  Storage of XML Data  XML Applications.
CSE3201/CSE4500 XPath. 2 XPath A locator for elements or attributes in an XML document. XPath expression gives direction.
Lecture 21 XML querying. 2 XSL (eXtensible Stylesheet Language) In HTML, default styling is built into browsers as tag set for HTML is predefined and.
Lecture 6 of Advanced Databases XML Schema, Querying & Transformation Instructor: Mr.Ahmed Al Astal.
XML By Dr.S.Sridhar, Ph.D.(JNUD), RACI(Paris, NICE), RMR(USA), RZFM(Germany) DIRECTOR ARUNAI ENGINEERING COLLEGE TIRUVANNAMALAI.
TDDD43 XML and RDF Slides based on slides by Lena Strömbäck and Fang Wei-Kleiner 1.
1/17 ITApplications XML Module Session 7: Introduction to XPath.
Lecture 6 of Advanced Databases XML Querying & Transformation Instructor: Mr.Eyad Almassri.
Computing & Information Sciences Kansas State University Friday, 17 Oct 2007CIS 560: Database System Concepts Lecture 21 of 42 Friday, 17 October 2008.
XP New Perspectives on XML Tutorial 6 1 TUTORIAL 6 XSLT Tutorial – Carey ISBN
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
Chapter 10: XML XML Structure of XML Data XML Document Schema Querying and Transformation Application Program Interfaces to XML Storage of XML Data.
XMLI Structure of XML Data Structure of XML Data XML Document Schema XML Document Schema XPATH XPATH.
1 CIS336 Website design, implementation and management (also Semester 2 of CIS219, CIS221 and IT226) Lecture 6 XSLT (Based on Møller and Schwartzbach,
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.
XQL, OQL and SQL Xia Tang Sixin Qian Shijun Shen Feb 18, 2000.
ECA 228 Internet/Intranet Design I XSLT Example. ECA 228 Internet/Intranet Design I 2 CSS Limitations cannot modify content cannot insert additional text.
Computing & Information Sciences Kansas State University Thursday, 15 Mar 2007CIS 560: Database System Concepts Lecture 24 of 42 Thursday, 15 March 2007.
Database Systems Part VII: XML Querying Software School of Hunan University
Temple University – CIS Dept. CIS616– Principles of Data Management V. Megalooikonomou XML ( based on slides by Silberschatz, Korth and Sudarshan at Bell.
XML Name: Niki Sardjono Class: CS 157A Instructor : Prof. S. M. Lee.
[ Part III of The XML seminar ] Presenter: Xiaogeng Zhao A Introduction of XQL.
Database System Concepts Bin Mu at Tongji University Chapter 10: XML.
1 XML Data Management XPath Principles Werner Nutt.
CIS750 – Seminar in Advanced Topics in Computer Science Advanced topics in databases – Multimedia Databases V. Megalooikonomou XML ( based on slides by.
XML Query: xQuery Reference: Xquery By Priscilla Walmsley, Published by O’Reilly.
More XML XPATH, XSLT CS 431 – February 23, 2005 Carl Lagoze – Cornell University.
©Silberschatz, Korth and Sudarshan10.1Database System Concepts XML Query Languages Notes Based on Chapter 10 of Database System Concepts.
1. XML Structure of XML Data XML Document Schema Querying and Transformation Application Program Interfaces to XML Storage of XML Data XML Applications.
Database System Concepts ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 10: XML.
XPath --XML Path Language Motivation of XPath Data Model and Data Types Node Types Location Steps Functions XPath 2.0 Additional Functionality and its.
Chapter 10: XML. XML Structure of XML Data XML Document Schema Querying and Transformation Application Program Interfaces to XML Storage of XML Data XML.
Chapter 8: XML. 2 XML Structure of XML Data XML Document Schema Querying and Transformation Application Program Interfaces to XML Storage of XML Data.
Database System Concepts ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 10: XML.
Chapter 10: XML. ©Silberschatz, Korth and Sudarshan10.2Database System ConceptsIntroduction XML: Extensible Markup Language Defined by the WWW Consortium.
Chapter 10: XML. ©Silberschatz, Korth and Sudarshan10.2Database System ConceptsIntroduction XML: Extensible Markup Language Defined by the WWW Consortium.
L14-S1 XML 2003 SJSU -- CmpE Database Design Dr. M.E. Fayad, Professor Computer Engineering Department, Room #283I College of Engineering San José State.
Chapter 10: XML Introduction  XML: Extensible Markup Language  Defined by the WWW Consortium (W3C)  Originally intended as a document.
1 XSL Transformations (XSLT). 2 XSLT XSLT is a language for transforming XML documents into XHTML documents or to other XML documents. XSLT uses XPath.
ADT 2010 Introduction to (XML, XPath &) XQuery Chapter 10 in Silberschatz, Korth, Sudarshan “Database System Concepts” Stefan Manegold
10.1 Chapter 10: XML Sections Problems 10.1, 10.2, 10.7 Find an example of using XML in a field of interest to you and describe it to the class.
Database System Concepts ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 10: XML.
XML: Extensible Markup Language
Chapter 23: XML Database System concepts,6th Ed.
CS 480: Database Systems Lecture 28 March 22, 2013.
{ XML Technologies } BY: DR. M’HAMED MATAOUI
Chapter 10: XML.
Chapter 10: XML.
More XML XML schema, XPATH, XSLT
Presentation transcript:

Querying and Transforming XML Data Translation of information from one XML schema to another Querying on XML data Above two are closely related, and handled by the same tools Standard XML querying/translation languages XPath Simple language consisting of path expressions XSLT Simple language designed for translation from XML to XML and XML to HTML XQuery An XML query language with a rich set of features

Tree Model of XML Data Query and transformation languages are based on a tree model of XML data An XML document is modeled as a tree, with nodes corresponding to elements and attributes Element nodes have child nodes, which can be attributes or subelements Text in an element is modeled as a text node child of the element Children of a node are ordered according to their order in the XML document Element and attribute nodes (except for the root node) have a single parent, which is an element node The root node has a single child, which is the root element of the document

XPath (1) XPath is used to address (select) parts of documents using path expressions A path expression is a sequence of steps separated by “/” Think of file names in a directory hierarchy Result of path expression: set of values that along with their containing elements/attributes match the specified path E.g. /bank-2/customer/customer_name evaluated on the bank-2 data we saw earlier returns <customer_name>Joe</customer_name> <customer_name>Mary</customer_name> E.g. /bank-2/customer/customer_name/text( ) returns the same names, but without the enclosing tags

XPath (2) The initial “/” denotes root of the document (above the top-level tag) Path expressions are evaluated left to right Each step operates on the set of instances produced by the previous step Selection predicates may follow any step in a path, in [ ] E.g. /bank-2/account[balance > 400] returns account elements with a balance value greater than 400 /bank-2/account[balance] returns account elements containing a balance subelement Attributes are accessed using “@” E.g. /bank-2/account[balance > 400]/@account_number returns the account numbers of accounts with balance > 400 IDREF attributes are not dereferenced automatically (more on this later)

Functions in XPath XPath provides several functions The function count() at the end of a path counts the number of elements in the set generated by the path E.g. /bank-2/account[count(./customer) > 2] Returns accounts with > 2 customers Also function for testing position (1, 2, ..) of node w.r.t. siblings Boolean connectives and and or and function not() can be used in predicates IDREFs can be referenced using function id() id() can also be applied to sets of references such as IDREFS and even to strings containing multiple references separated by blanks E.g. /bank-2/account/id(@owner) returns all customers referred to from the owners attribute of account elements.

More XPath Features Operator “|” used to implement union E.g. /bank-2/account/id(@owner) | /bank-2/loan/id(@borrower) Gives customers with either accounts or loans However, “|” cannot be nested inside other operators. “//” can be used to skip multiple levels of nodes E.g. /bank-2//customer_name finds any customer_name element anywhere under the /bank-2 element, regardless of the element in which it is contained. A step in the path can go to parents, siblings, ancestors and descendants of the nodes generated by the previous step, not just to the children “//”, described above, is a short from for specifying “all descendants” “..” specifies the parent. doc(name) returns the root of a named document

Traversing the source tree Templates definitions are applied to elements of source document First Template matching a pattern chosen Pattern subset of XPath expressions can match elements and attributes can use node tests and predicates XPath Simple language to identify parts of an XML document Similar to paths in a file system

Traversing the source tree The XPath data model XML documents consists of seven types Root node Elements Attribute Text Namespace Comment Processing instruction <?xml-stylesheet type=“text/xsl”?> <!-- comments go here --> <amount vendor=“314” xmlns=“urn:wyeast-net: invoice> 8989.00 </amount>

XPath Data Model XML structured can viewed as tree with different types of nodes root Processing instruction <?xml-stylesheet type=“text/xsl”?> comment <!-- comments go here --> element amount attribute vendor=“314” namespace xmlns=“urn:wyeast-net: invoice> text 8989.00

XPath Data Model Location step Description \ The root node element-name The name of an element text() element’s text comment() a comment @attribute-name The name of an attribute node() any node * @* any element name any attribute name

XPath Data Model Result of an XPath location: duplicate free set of nodes /movies/movie: the set of all movie elements /movies/movie/rating: the set of all rating elements “<rating>3</rating>”, “<rating>2</rating>” /movies/movie/title/@lang: the set of all language attribute names <movies> <movie> <title>Man In Black</title> <rating>3</rating> </movie> <title lang=“en”>Batman</title> <title lang=“ko”>Bateman</title> <rating>2</rating> </movies>

XPath Data Model context-node when template is applied: Currently selected and processed node Each location step is evaluated with respect to a context-node The context-node depends on previous results Initially: root node is context node Context-nodes used by XSLT processor to keep track of current positions for matching templates Is similar to current directory in a command line shell Location step for context-node “.” (similar to file paths) when template is applied: context-node moves to first node of the matched result set Subsequent templates are matched with respect to new context-node

XPath Data Model current node current node list current position Identical to context-node, except when using predicates (later) current node list Sequence of nodes Is ordered (list instead of set) Ordered forward or reverse (document order) to occurrence in document Obtained, e.g., by “select” attribute current position a nonzero, positive integer Indicates position in the current node list for processing context size Number of nodes in current node list

XQuery XQuery is a general purpose query language for XML data Currently being standardized by the World Wide Web Consortium (W3C) The textbook description is based on a January 2005 draft of the standard. The final version may differ, but major features likely to stay unchanged. XQuery is derived from the Quilt query language, which itself borrows from SQL, XQL and XML-QL XQuery uses a for … let … where … order by …result … syntax for  SQL from where  SQL where order by  SQL order by result  SQL select let allows temporary variables, and has no equivalent in SQL

FLWOR Syntax in XQuery For clause uses XPath expressions, and variable in for clause ranges over values in the set returned by XPath Simple FLWOR expression in XQuery find all accounts with balance > 400, with each result enclosed in an <account_number> .. </account_number> tag for $x in /bank-2/account let $acctno := $x/@account_number where $x/balance > 400 return <account_number> { $acctno } </account_number> Items in the return clause are XML text unless enclosed in {}, in which case they are evaluated Let clause not really needed in this query, and selection can be done In XPath. Query can be written as: for $x in /bank-2/account[balance>400] return <account_number> { $x/@account_number } </account_number>

Joins Joins are specified in a manner very similar to SQL for $a in /bank/account, $c in /bank/customer, $d in /bank/depositor where $a/account_number = $d/account_number and $c/customer_name = $d/customer_name return <cust_acct> { $c $a } </cust_acct> The same query can be expressed with the selections specified as XPath selections: for $a in /bank/account $c in /bank/customer $d in /bank/depositor[ account_number = $a/account_number and customer_name = $c/customer_name]