An Introduction to XPath Language

Similar documents
XML and Data Management

Markup Languages and Semistructured Data - SS 02

Creating a TEI-Based Website with the exist XML Database

Structured vs. unstructured data. Motivation for self describing data. Enter semistructured data. Databases are highly structured

Unified XML/relational storage March The IBM approach to unified XML/relational databases

Semistructured data and XML. Institutt for Informatikk INF Ahmet Soylu

Storing and Querying Ordered XML Using a Relational Database System

Quiz! Database Indexes. Index. Quiz! Disc and main memory. Quiz! How costly is this operation (naive solution)?

6. SQL/XML. 6.1 Introduction. 6.1 Introduction. 6.1 Introduction. 6.1 Introduction. XML Databases 6. SQL/XML. Creating XML documents from a database

Java and XML parsing. EH2745 Lecture #8 Spring

High Performance XML Data Retrieval

XML Databases 6. SQL/XML

Chapter 3: XML Namespaces

XSLT Mapping in SAP PI 7.1

XML and Data Integration

WebSphere Business Monitor

XML: extensible Markup Language. Anabel Fraga

XML Schema Definition Language (XSDL)

Instant SQL Programming

04 XML Schemas. Software Technology 2. MSc in Communication Sciences Program in Technologies for Human Communication Davide Eynard

Introduction to XML. Data Integration. Structure in Data Representation. Yanlei Diao UMass Amherst Nov 15, 2007

DTD Tutorial. About the tutorial. Tutorial

Agents and Web Services

Instant YANG. The Basics. Hakan Millroth, Tail- f Systems ( hakan@tail- f.com)

Caching XML Data on Mobile Web Clients

What's new in 3.0 (XSLT/XPath/XQuery) (plus XML Schema 1.1) Michael Kay Saxonica

Data Integration through XML/XSLT. Presenter: Xin Gu

Start learning XPath! XPath Nodes This chapter defines the different types of nodes in XPath and the relationship of nodes.

SQL DATA DEFINITION: KEY CONSTRAINTS. CS121: Introduction to Relational Database Systems Fall 2015 Lecture 7

Deferred node-copying scheme for XQuery processors

A Workbench for Prototyping XML Data Exchange (extended abstract)

Structured vs. unstructured data. Semistructured data, XML, DTDs. Motivation for self-describing data

Introduction to Ingeniux Forms Builder. 90 minute Course CMSFB-V6 P

Database Design Patterns. Winter Lecture 24

Full and Complete Binary Trees

Discovering SQL. Wiley Publishing, Inc. A HANDS-ON GUIDE FOR BEGINNERS. Alex Kriegel WILEY

INTRO TO XMLSPY (IXS)

XML Digital Signature Implementation Guide

How To Use Query Console

IoT-Ticket.com. Your Ticket to the Internet of Things and beyond. IoT API

Data Structures Fibonacci Heaps, Amortized Analysis

IBM DB2 XML support. How to Configure the IBM DB2 Support in oxygen

PES Institute of Technology-BSC QUESTION BANK

XML Data Integration

Terms and Definitions for CMS Administrators, Architects, and Developers

metaengine DataConnect For SharePoint 2007 Configuration Guide

T XML in 2 lessons! %! " #$& $ "#& ) ' */,: -.,0+(. ". "'- (. 1

Social Relationship Analysis with Data Mining

Extending the Linked Data API with RDFa

Schematron Validation and Guidance

Managing large sound databases using Mpeg7

Database & Information Systems Group Prof. Marc H. Scholl. XML & Databases. Tutorial. 11. SQL Compilation, XPath Symmetries

TR-154 TR-069 Data Model XML User Guide

Data Integrator. Pervasive Software, Inc B Riata Trace Parkway Austin, Texas USA

Qlik REST Connector Installation and User Guide

User Application: Design Guide

ICAB4136B Use structured query language to create database structures and manipulate data

Web Services Technologies

CS 2112 Spring Instructions. Assignment 3 Data Structures and Web Filtering. 0.1 Grading. 0.2 Partners. 0.3 Restrictions

Regular Expressions and Automata using Haskell

Database trends: XML data storage

CMPSCI 250: Introduction to Computation. Lecture #19: Regular Expressions and Their Languages David Mix Barrington 11 April 2013

HireDesk API V1.0 Developer s Guide

Experiences with JSON and XML Transformations IBM Submission to W3C Workshop on Data and Services Integration October , Bedford, MA, USA

Translating XQuery expressions to Functional Queries in a Mediator Database System

Introduction to XML Applications

Object Oriented Databases. OOAD Fall 2012 Arjun Gopalakrishna Bhavya Udayashankar

Advanced Information Management

Spectrum Technology Platform. Version 9.0. Enterprise Data Integration Guide

Extending XSLT with Java and C#

XML. Document Type Definitions XML Schema

Sorting Hierarchical Data in External Memory for Archiving

XML Programming with PHP and Ajax

City of Mercer Island Request for Proposals for Document Scanning and Indexing

Customizing MISys Manufacturing Reports Using ADO-XML 6/3/2013

Efficient Data Structures for Decision Diagrams

AN ENHANCED DATA MODEL AND QUERY ALGEBRA FOR PARTIALLY STRUCTURED XML DATABASE

Application of XML Tools for Enterprise-Wide RBAC Implementation Tasks

Presentation / Interface 1.3

An XML Based Data Exchange Model for Power System Studies

RDF y SPARQL: Dos componentes básicos para la Web de datos

Oracle Forms Services Secure Web.Show_Document() calls to Oracle Reports

12 File and Database Concepts 13 File and Database Concepts A many-to-many relationship means that one record in a particular record type can be relat

Exchanger XML Editor - Canonicalization and XML Digital Signatures

Chapter 2: Designing XML DTDs

Bitrix Site Manager 4.1. User Guide

CHAPTER 1 INTRODUCTION

The following themes form the major topics of this chapter: The terms and concepts related to trees (Section 5.2).

Transcription:

VICTORIA UNIVERSITY OF WELLINGTON Te Whare Wananga o te Upoko o te Ika a Maui An Introduction to XPath Language Lecturer : Pavle Mogin COMP 442 Issues in Databases and Information Systems Plan For XPath Language What is XPath? What is XPath used for Basic XPath syntax Abbreviated syntax Redings: XML Path Language (XPath) Version 1.0 http://www.w3.org/tr/1999/rec-xpath-19991116 COMP 442 Issues in Databases and Information Systems XPath Language_04 1

What is XPath XPath is a language for specifying navigation within an XML document It also provides basic facilities for manipulating strings, numbers, and booleans XPath gets its name from its use of path notation as in URLs for navigating through the hierarchical structure of an XML document XPath models an XML document as a tree of nodes Most common nodes are: elements, attributes, text XPath defines a way to compute a string value for each type of node COMP 442 Issues in Databases and Information Systems XPath Language_04 2 What is XPath used for XPath is used to define paths in an XML document in: XSL Transformations (XSLT), XPointer, XQuery Language, Within XML Schema for specifying special constraints like: key, referential integrity, and unique A restricted subset of XPath is used in XQuery and for specifying context of XML Schema constraints We are almost exclusively interested in using XPath within XQuery and for declaring constraints COMP 442 Issues in Databases and Information Systems XPath Language_04 3

XPath Location Paths Navigation through an XML document is declared using XPath expressions Although Location Paths are not the most general grammatical construct in the language, they are most important construct and we shall pay our exclusive attention to them Location paths can be expressed using either an unabbreviated or an abbreviated syntax There are two kinds of location paths: Relative location paths and Absolute location paths COMP 442 Issues in Databases and Information Systems XPath Language_04 4 Unabbreviated Syntax of Location Paths A relative location path has the following syntax: Path ::= Step 1 /Step 2 //Step n where each Step is a triple (Axis, Node-test, Predicate) and is defined as follows: Step ::= Axis:: Node-test Predicate* The axis specifies the direction to move in the document tree The node test selects nodes along the specified axis, and The predicates (if any) filter the nodes selected Separators / between two subsequent steps indicate a direct parent-child relationship between nodes involved in the steps COMP 442 Issues in Databases and Information Systems XPath Language_04 5

Evaluation of a Relative Location Path A relative location path is evaluated step by step, from left to right A step is applied to a single node, so called context node The application of a step on a context node selects a set of result nodes Each node of a result set is then used as a context node in the following step The result of an expression is the union of node-sets selected by the last step Suppose a location path is declared (in an XML schema) within an element E c declaration, then the Step 1 will be applied on the node-set of the type E c (each node of the type E c will be used as the first context node) COMP 442 Issues in Databases and Information Systems XPath Language_04 6 Result of a Relative Location Path The result of an expression is the union of node-sets selected by the last step Elements of a node-set are nodes of different types: Elements, Attributes, Text, Comments, Processing Instructions, According to the Standard: A string value of a node is the concatenation of the string values of all text descendants of the node We shall obey to that definition for all node types except for complex element nodes, where we shall use the node identifier instead COMP 442 Issues in Databases and Information Systems XPath Language_04 7

Absolute Location Path An absolute location path consists of a / optionally followed by a relative location path A leading / itself selects the root node of the document as the context node Formally: LocationPath ::= RelativeLocationPath AbsoluteLocationPath AbsoluteLocationPath ::= / RelativeLocationPath RelativeLocationPath ::= Step RelativeLocationPath / Step Both relative and absolute location path may be expressed either using an unabbreviated or abbreviated syntax COMP 442 Issues in Databases and Information Systems XPath Language_04 8 A Class XML Document <?xml version= 1.0 standalone= yes?> <CLASS name= COMP442 > <LECTURER>Pavle</LECTURER> <STUDENT no_of_pts= 20.0 origin= International > <NAME>Ahmed</NAME> <ASSIGNMENT no= 1 >10.0</ASSIGNMENT> <ASSIGNMENT no= 2 >10.0</ASSIGNMENT> </STUDENT> <STUDENT no_of_pts= 0.0 origin= Domestic > </STUDENT> </CLASS> <NAME>Bad Student</NAME> COMP 442 Issues in Databases and Information Systems XPath Language_04 9

A Class Document Tree name &1 CLASS COMP442 LECTURER STUDENT &2 &3 STUDENT &7 ASSIGNMENT NAME Pavle no_of_pts origin &4 &5 &6 no_of_pts origin &8 NAME 20.0 International Ahmed no 10.0 no 10.0 0.0 Domestic Bad Student 1 2 COMP 442 Issues in Databases and Information Systems XPath Language_04 10 Axis of an XPath Step Within an XPath step, Axis specifies direction in which to navigate through a document For example, the step: child::student where Axis = child:: and Node-test = STUDENT would select all child nodes (of a context node) that have the name STUDENT The XPath supports 12 different axes for navigation The child:: axis is most commonly used Some of the others are: attribute:: (selects attributes of a context node), descendant:: (selects descendant nodes of a context node), descendant-or-self:: parent:: (selects the parent node of a context node), self:: (selects the context node itself), COMP 442 Issues in Databases and Information Systems XPath Language_04 11

The Node-test of an XPath Step A Node-test specifies a simple test on XML nodes found along the steps axis The nodes that pass that test are candidates for the next step The most commonly used Node-test is element name In the step child::student, STUDENT is an element name Other often used node tests are *, which evaluates to true for all element nodes, and attribute test A step child::* will choose all subelements of a context node A step attribute:: name will select the name attribute of a context node There are also Node-tests for: Namespaces, Text nodes, Comments, and Processing instructions COMP 442 Issues in Databases and Information Systems XPath Language_04 12 Predicates of a Step An XPath step can also include a sequence of predicates The predicates are applied to the nodes selected by Node-test Only nodes that evaluate to true for all predicates will belong to the result nodeset of the step A predicate compares a node property with a value using operators from the set {=, <, >,<, >,!=,} A node property can be: The value of an attribute, The value of PCDATA of an element, or The sibling order value of a node (returned by the function position()) COMP 442 Issues in Databases and Information Systems XPath Language_04 13

Examples of XPath Predicates child:: STUDENT[position()=2] selects the second STUDENT child element of the context node child::student/attribute::[origin= Inter national ][no_of_pts> 35 ] selects all student children of the context node that are international and have more than 35 points child::student/child::name= Ahmed selects the STUDENT children of the context node that have a NAME child with a string value equal to Ahmed COMP 442 Issues in Databases and Information Systems XPath Language_04 14 Abbreviated Syntax of Location Path (1) The most important abbreviation is that child:: axis can be omitted from a location step In effect, child:: is the default axis For example, STUDENT/NAME is a short for child:: STUDENT/child::NAME There is also an abbreviation for attributes: attribute:: can be abbreviated to @ For example, STUDENT[@origin= Domestic ] is short for child::student[attribute:: origin= Domestic ] and will select all STUDENT children of the context node whose origin is Domestic COMP 442 Issues in Databases and Information Systems XPath Language_04 15

Abbreviated Syntax of Location Path (2) If a predicate expression evaluates to an integer value that value is considered to be the position of the node selected For example, STUDENT[2] step would select the second STUDENT child of the context node An empty step // is also a frequently used abbreviation, it specifies that the element that follows may be nested anywhere within the document For example, //STUDENT would select all student nodes anywhere within the document COMP 442 Issues in Databases and Information Systems XPath Language_04 16 Abbreviated Syntax of Location Path (3) A location step of. is short for self::node(), where self:: refers to the context node and node() returns nodes of any type For example,.//student is short for self::node()/descendant-orself::node()/child::student and will select all STUDENT elements that are children of the context node itself or any of its descendants A location step of.. is short for parent::node() For example,../lecturer is short for parent::node()/child::lecturer and will select all LECTURER children of the parent of the context node COMP 442 Issues in Databases and Information Systems XPath Language_04 17

Declaring Location Path in XML Schema A location path is declared in an XML schema using the attribute path within the definition of an element Let a location path p be declared within an element E, then the element E is the context of the path p The selection of the context element has to provide for an unambiguous path evaluation Next we are going to consider a couple of example location path declarations using abbreviated syntax COMP 442 Issues in Databases and Information Systems XPath Language_04 18 Location Path Examples (1) Example 1: <xsd:element name= CLASS > < xpath= STUDENT/NAME > </xsd:element> Result = {Ahmed, Bad Student} Example 2 <xsd:element name= CLASS > <xpath= STUDENT/ASSIGNMENT[@no= 1 ] > </xsd:element> Result = {10} COMP 442 Issues in Databases and Information Systems XPath Language_04 19

Location Path Examples (2) Example 3: <xsd:element name= STUDENT > <xpath= //LECTURER > </xsd:element> Result = {Pavle} Example 4 <xsd:element name= CLASS > <xpath= STUDENT[ASSIGNMENT= 10 ] [@no= 2 ]/NAME > </xsd:element> Result = {Ahmed} COMP 442 Issues in Databases and Information Systems XPath Language_04 20 Location Path Examples (3) Example 5: <xsd:element name= STUDENT > <xpath=.. > </xsd:element> Result = {&1} Example 6 <xsd:element name= CLASS > <xpath= STUDENT > </xsd:element> Result = {&3, &7} COMP 442 Issues in Databases and Information Systems XPath Language_04 21

Summary (1) XPath is a language for specifying navigation within an XML document XPath models an XML document as a tree of nodes A restricted subset of XPath called LocationPath is used in XQuery and for specifying context of XML Schema constraints A location path has the following syntax: Path ::= Step 1 /Step 2 //Step n where each Step is a triple (Axis, Node-test, Predicate): The axis specifies the direction to move in the document tree The node test selects nodes along the specified axis, and The predicates (if any) filter the nodes selected An abbreviated syntax is used to declare navigation through an XML document in XQuery and when defining XML constraints COMP 442 Issues in Databases and Information Systems XPath Language_04 22 Summary (2) A location path can be either: Relative, or Absolute A relative location path is declared with regard to a context node and its evaluation stars from this node A relative location path is declared in an XML schema using the attribute path within the declaration of an element This element is the context of the relative location path declared by path COMP 442 Issues in Databases and Information Systems XPath Language_04 23