TDDD43. Theme 1.2: XML query languages. Fang Wei- Kleiner h?p:// TDDD43

Similar documents
XPath and XQuery. Introduction to Databases CompSci 316 Fall 2018

XML, DTD, and XPath. Announcements. From HTML to XML (extensible Markup Language) CPS 116 Introduction to Database Systems. Midterm has been graded

XML databases. Jan Chomicki. University at Buffalo. Jan Chomicki (University at Buffalo) XML databases 1 / 9

Semi-structured Data. 8 - XPath

One of the main selling points of a database engine is the ability to make declarative queries---like SQL---that specify what should be done while

XML & Databases. Tutorial. 3. XPath Queries. Universität Konstanz. Database & Information Systems Group Prof. Marc H. Scholl

XPath. Lecture 36. Robb T. Koether. Wed, Apr 16, Hampden-Sydney College. Robb T. Koether (Hampden-Sydney College) XPath Wed, Apr 16, / 28

Querying XML. COSC 304 Introduction to Database Systems. XML Querying. Example DTD. Example XML Document. Path Descriptions in XPath

H2 Spring B. We can abstract out the interactions and policy points from DoDAF operational views

Course: The XPath Language

Informatics 1: Data & Analysis

XML Data Management. 5. Extracting Data from XML: XPath

Seleniet XPATH Locator QuickRef

Pre-Discussion. XQuery: An XML Query Language. Outline. 1. The story, in brief is. Other query languages. XML vs. Relational Data

XPath. Asst. Prof. Dr. Kanda Runapongsa Saikaew Dept. of Computer Engineering Khon Kaen University

XML Technologies. Doc. RNDr. Irena Holubova, Ph.D. Web pages:

Navigating Input Documents Using Paths4

XPath and XSLT. Overview. Context. Context The Basics of XPath. XPath and XSLT. Nodes Axes Expressions. Stylesheet templates Transformations

Course: The XPath Language

XPath Expression Syntax

XPath. by Klaus Lüthje Lauri Pitkänen

XML: Extensible Markup Language

Manipulating XML Trees XPath and XSLT. CS 431 February 18, 2008 Carl Lagoze Cornell University

Query Languages for XML

9/2/2010. Today s lecture. Advanced databases and data models: Theme2: Query languages. Semi-structured data - properties. Types of query languages

XQuery. Announcements (March 21) XQuery. CPS 216 Advanced Database Systems

Informatics 1: Data & Analysis

XML Data Management. 6. XPath 1.0 Principles. Werner Nutt

Big Data 12. Querying

XML. Semi-structured data (SSD) SSD Graphs. SSD Examples. Schemas for SSD. More flexible data model than the relational model.

Outline of this part (I) Part IV. Querying XML Documents. Querying XML Documents. Outline of this part (II)

Big Data 10. Querying

Copyright 2007 Ramez Elmasri and Shamkant B. Navathe. Slide 27-1

XSLT: How Do We Use It?

Reading XML: Introducing XPath. Andrew Walker

XPath Lecture 34. Robb T. Koether. Hampden-Sydney College. Wed, Apr 11, 2012

Querying XML Data. Querying XML has two components. Selecting data. Construct output, or transform data

EMERGING TECHNOLOGIES

Burrows & Langford Appendix D page 1 Learning Programming Using VISUAL BASIC.NET

516. XSLT. Prerequisites. Version 1.2

Databases and Information Systems 1. Prof. Dr. Stefan Böttcher

XPath an XML query language

Databases and Information Systems XML storage in RDBMS and core XPath implementation. Prof. Dr. Stefan Böttcher

XML and information exchange. XML extensible Markup Language XML

September 3, 2001 XML Processing

Semantic Characterizations of XPath

Introduction to XPath

An Algorithm for Streaming XPath Processing with Forward and Backward Axes

~ Ian Hunneybell: DIA Revision Notes ~

DBS2: Exkursus XQuery and XML-Databases. Jan Sievers Jens Hündling Lars Trieloff

XPath. Mario Alviano A.Y. 2017/2018. University of Calabria, Italy 1 / 21

COPYRIGHTED MATERIAL. Contents. Part I: Introduction 1. Chapter 1: What Is XML? 3. Chapter 2: Well-Formed XML 23. Acknowledgments

2006 Martin v. Löwis. Data-centric XML. XPath

Presentation. Separating Content and Presentation Cascading Style Sheets (CSS) XML and XSLT

Chapter 1: Semistructured Data Management XML

An introduction to searching in oxygen using XPath

Comp 336/436 - Markup Languages. Fall Semester Week 9. Dr Nick Hayward

Informatics 1: Data & Analysis

Navigation. 3.1 Introduction. 3.2 Paths

Chapter 1: Semistructured Data Management XML

Databases and Information Systems 1 - XPath queries on XML data streams -

Example using multiple predicates

Introduction to XQuery and XML Databases

Progress Report on XQuery

XML and Databases. Lecture 10 XPath Evaluation using RDBMS. Sebastian Maneth NICTA and UNSW

Computer Science E-259

Parte IV: XPATH. Prof. Riccardo Torlone

BASI DI DATI II 2 modulo

Introduction p. 1 An XML Primer p. 5 History of XML p. 6 Benefits of XML p. 11 Components of XML p. 12 BNF Grammar p. 14 Prolog p. 15 Elements p.

Web Services Week 3. Fall Emrullah SONUÇ. Department of Computer Engineering Karabuk University

Navigating an XML Document

ADT 2009 Other Approaches to XQuery Processing

XML. Document Type Definitions. Database Systems and Concepts, CSCI 3030U, UOIT, Course Instructor: Jarek Szlichta

XML Query Languages. Yanlei Diao UMass Amherst April 22, Slide content courtesy of Ramakrishnan & Gehrke, Donald Kossmann, and Gerome Miklau

4D2b Navigating an XML Document

Query equivalence and optimization

XPath. Web Data Management and Distribution. Serge Abiteboul Philippe Rigaux Marie-Christine Rousset Pierre Senellart

Notes on XML and XQuery in Relational Databases

XML in Databases. Albrecht Schmidt. al. Albrecht Schmidt, Aalborg University 1

EMERGING TECHNOLOGIES

Xpath Xlink Xpointer Xquery

COMP9319 Web Data Compression & Search. Cloud and data optimization XPath containment Distributed path expression processing

ADT 2005 Lecture 7 Chapter 10: XML

XML Databases 5. XML Query Languages,

5. XML Query Languages I. 5.1 Introduction. 5.1 Introduction. 5.1 Introduction. 5.1 Introduction. XML Databases 5. XML Query Languages,

META-MODEL SEARCH: USING XPATH FOR SEARCHING DOMAIN-SPECIFIC MODELS RAJESH SUDARSAN

XML and Databases. Outline. Outline - Lectures. Outline - Assignments. from Lecture 3 : XPath. Sebastian Maneth NICTA and UNSW

xmlns:gu=" xmlns:uky="

Overview. Structured Data. The Structure of Data. Semi-Structured Data Introduction to XML Querying XML Documents. CMPUT 391: XML and Querying XML

A Structural Numbering Scheme for XML Data

XML Wrap-up. CS 431 March 1, 2006 Carl Lagoze Cornell University

Introduction. " Documents have tags giving extra information about sections of the document

Introduction. " Documents have tags giving extra information about sections of the document

XPath. Contents. Tobias Schlitt Jakob Westho November 17, 2008

Index-Driven XQuery Processing in the exist XML Database

8/24/2010. Internet. Advanced databases and data models: Theme1: Semi structured data. What is the problem? In this course:

XML: extensible Markup Language

Part XII. Mapping XML to Databases. Torsten Grust (WSI) Database-Supported XML Processors Winter 2008/09 321

DOM Interface subset 1/ 2

M359 Block5 - Lecture12 Eng/ Waleed Omar

Transcription:

Theme 1.2: XML query languages Fang Wei- Kleiner h?p://www.ida.liu.se/~

Query languages for XML Xpath o Path expressions with conditions o Building block of other standards (XQuery, XSLT, XLink, XPointer, etc.) Xquery o XPath + full- fledged SQL- like query language XSLT o XPath + transformation templates

XPath XPath specifies path expressions that match XML data by navigating down (and occasionally up and across) the tree Example o Query: /minimodel/listofreactions/reaction Like a UNIX path o Result: all author elements reachable from root via the path /minimodel/listofreactions/reaction

Basic Xpath constructs / separator between steps in a path name matches any child element with this tag name * matches any child element @name matches the a?ribute with this name @* matches any a?ribute // matches any descendent element or the current element itself. matches the current element.. matches the parent element

Simple XPath examples All reactions /minimodel/listofreactions/reaction All reaction names /minimodel/listofreactions/reaction/@name All reaction elements, anywhere in the document //reaction All species id, anywhere in the document //species/@id Species of the minimodel /minimodel/*/species

Predicates in path expressions [condition] matches the current element if condition evaluates to true on the current element Species in blood compartment /minimodel//species[@compartment= blood ] Reactions with listofproducts as child element //reaction[listofproducts] Name of species in blood compartment /minimodel//species[@compartment= blood ]/@name

Predicates Predicates can have and s and or s Species with id as en and compartment as cell //species[@id= en and @compartment= cell ] Species with id as en or compartment as cell //species[@id= en or @compartment= cell ]

Predicates involving nodesets /minimodel/listofspecies/[species/@compartment= cell ] o There may be multiple species element, so species/@compartment in general returns a node- set (in XPath terminology) o The predicate evaluates to true as long as it evaluates true for at least one node in the node- set, i.e., at least one species has a compartment with value cell Tricky query /minimodel/listofspecies/[species/@compartment= cell and species/@compartment!= cell ]

XPath functions contains(x, y) true if string x contains string y count(node- set) counts the number nodes in node- set position() returns the context position (roughly, the position of the current node in the node- set containing it) last() returns the context size (roughly, the size of the node- set containing the current node) name() returns the tag name of the current element

More examples All elements whose tag names contain species //*[contains(name(), species )] Name of the first species /minimodel/listofspecies/species[position()=1]/@name A shorthand: /minimodel/listofspecies/species[1]/@name Name of the last species /minimodel/listofspecies/species[position()=last()]/@name Lists with fewer than 10 species /minimodel/listofspecies [count(species)<10] All elements whose parent s tag name is not reaction //*[name()!= reaction ]/*

General XPath location steps Technically, each XPath query consists of a series of location steps separated by / Each location step consists of o An axis: one of self, attribute, parent, child, ancestor, ancestor-or-self, descendant, descendant-or-self, following, following-sibling, preceding, precedingsibling, and namespace A node- test: either a name test (e.g., reaction, *) or a type test (e.g., text(), node(), comment()), separated from the axis by :: Zero of more predicates (or conditions) enclosed in square brackets

Example Verbose (axis, node test, predicate): /child::minimodel/descendant-or-self::node()/child::species[attribute::id= sug1 ] Abbreviated: /minimodel//species[@id= sug1 ] child is the default axis // stands for /descendant-or-self::node()/

Example Which of the following queries correctly find the third speciesreferences in the entire input document? //speciesreference [position()=3] o Finds all third speciesreferences (for each of its parent element) /descendant-or-self::node()[name()= speciesreference and position()=3] o Returns the third element in the document if it is a speciesreferences /descendant-or-self::node()[name()= speciesreference ][position()=3] o After the first condition is passed, the evaluation context changes Context size: # of nodes that passed the first condition Context position: position of the context node within the list of nodes

Technical details of evaluation Given a context node, evaluate a location path as follows: 1. Start with node- set N = {context node} 2. For each location step, from left to right: o U ß ø o For each node n in N: Using n as the context node, compute a node- set N from the axis and the node- test Each predicate in turn filters N o For each node n in N, evaluate predicate with the following context: Context node is n Context size is the number of nodes in N Context position is the position of n within N U = U U N o N ß U 3. Return N

XQuery XPath + full- fledged SQL- like query language XQuery expressions can be o XPath expressions o FLWOR expressions o Quantified expressions o Aggregation, sorting, and more An XQuery expression in general can return a new result XML document Compare with an XPath expression, which always returns a sequence of nodes from the input document or atomic values (boolean, number, string, etc.)

FLWR expression <result>{ for $s in doc( minimodel.xml )/minimodel//species let $n := $s/@name where $s/@compartment = cell return <cellspecies> { $s/@id } { $n } </cellspecies> }</result> for: loop let: assignment where: filter condition return: result construction

FLWR expression

Join in XQuery

XQuery functions Note: recursion