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

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

XQuery FLOWR Expressions Lecture 35

Minimal Spanning Trees

The Critical-Path Algorithm

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 Attributes. Lecture 33. Robb T. Koether. Hampden-Sydney College. Wed, Apr 25, 2018

The Decreasing-Time Algorithm

DTDs and XML Attributes

XML and AJAX Lecture 28

while Loops Lecture 13 Sections Robb T. Koether Wed, Sep 26, 2018 Hampden-Sydney College

Aggregation. Lecture 7 Section Robb T. Koether. Hampden-Sydney College. Wed, Jan 29, 2014

Stack Applications. Lecture 27 Sections Robb T. Koether. Hampden-Sydney College. Wed, Mar 29, 2017

PHP Queries and HTML Forms Lecture 23

Rotations and Translations

Seleniet XPATH Locator QuickRef

Webpage Navigation. Lecture 27. Robb T. Koether. Hampden-Sydney College. Mon, Apr 2, 2018

Boolean Expressions. Lecture 31 Sections 6.6, 6.7. Robb T. Koether. Hampden-Sydney College. Wed, Apr 8, 2015

XSLT. Lecture 38. Robb T. Koether. Mon, Apr 21, Hampden-Sydney College. Robb T. Koether (Hampden-Sydney College) XSLT Mon, Apr 21, / 26

Binary Tree Applications

Insertions, Deletions, and Updates

Form Validation. Lecture 25. Robb T. Koether. Hampden-Sydney College. Wed, Mar 23, 2018

The Coefficient of Determination

Scheduling and Digraphs

Sampling Distribution Examples Sections 15.4, 15.5

Recursive Sequences. Lecture 24 Section 5.6. Robb T. Koether. Hampden-Sydney College. Wed, Feb 27, 2013

Recursive Sequences. Lecture 24 Section 5.6. Robb T. Koether. Hampden-Sydney College. Wed, Feb 26, 2014

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

The string Class. Lecture 21 Sections 2.9, 3.9, Robb T. Koether. Wed, Oct 17, Hampden-Sydney College

Introduction to Databases

LR Parsing - Conflicts

Street-Routing Problems

Function Definition Syntax Tree

Solving Recursive Sequences by Iteration

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

The Traveling Salesman Problem Nearest-Neighbor Algorithm

Recursive Descent Parsers

XML. Lecture 29. Robb T. Koether. Fri, Mar 28, Hampden-Sydney College. Robb T. Koether (Hampden-Sydney College) XML Fri, Mar 28, / 23

jquery Lecture 34 Robb T. Koether Wed, Apr 10, 2013 Hampden-Sydney College Robb T. Koether (Hampden-Sydney College) jquery Wed, Apr 10, / 29

Semi-structured Data. 8 - XPath

Basic PHP. Lecture 19. Robb T. Koether. Hampden-Sydney College. Mon, Feb 26, 2108

The Graphics Pipeline

Density Curves Sections

The Class Construct Part 1

The Pairwise-Comparison Method

Boxplots. Lecture 17 Section Robb T. Koether. Hampden-Sydney College. Wed, Feb 10, 2010

The Traveling Salesman Problem Brute Force Method

Linked Lists. Lecture 16 Sections Robb T. Koether. Hampden-Sydney College. Wed, Feb 22, 2017

Total Orders. Lecture 41 Section 8.5. Robb T. Koether. Hampden-Sydney College. Mon, Apr 8, 2013

Building the Abstract Syntax Trees

XQuery Constructors and Joins Lecture 36

Scope and Parameter Passing

Relational Databases

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

Displaying Distributions - Quantitative Variables

Informatics 1: Data & Analysis

The Plurality-with-Elimination Method

Recursion. Lecture 2 Sections Robb T. Koether. Hampden-Sydney College. Wed, Jan 17, 2018

Programming Languages

Programming Languages

Operators. Lecture 12 Section Robb T. Koether. Hampden-Sydney College. Fri, Feb 9, 2018

Magnification and Minification

The Graphics Pipeline

Scope and Parameter Passing

PHP Querying. Lecture 21. Robb T. Koether. Hampden-Sydney College. Fri, Mar 2, 2018

The Projection Matrix

Implementing Linked Lists

Regular Expressions. Lecture 10 Sections Robb T. Koether. Hampden-Sydney College. Wed, Sep 14, 2016

Binary Tree Implementation

Friends and Unary Operators

Pointers. Lecture 1 Sections Robb T. Koether. Hampden-Sydney College. Wed, Jan 14, 2015

The Normal Distribution

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

Triggers. Lecture 14. Robb T. Koether. Hampden-Sydney College. Wed, Feb 14, 2018

Binary Tree Implementation

Abstract Data Types. Lecture 23 Section 7.1. Robb T. Koether. Hampden-Sydney College. Wed, Oct 24, 2012

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

Selections. Lecture 4 Sections Robb T. Koether. Hampden-Sydney College. Wed, Jan 22, 2014

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

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

Stack Applications. Lecture 25 Sections Robb T. Koether. Hampden-Sydney College. Mon, Mar 30, 2015

List Iterators. Lecture 27 Section Robb T. Koether. Hampden-Sydney College. Wed, Apr 8, 2015

List Iterator Implementation

Recursion. Lecture 26 Sections , Robb T. Koether. Hampden-Sydney College. Mon, Apr 6, 2015

Nondeterministic Programming in C++

Inheritance: The Fundamental Functions

Navigating Input Documents Using Paths4

List Iterators. Lecture 34 Section Robb T. Koether. Hampden-Sydney College. Wed, Apr 24, 2013

The CYK Parsing Algorithm

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

Introduction to Databases

Ambient and Diffuse Light

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

The Constructors. Lecture 7 Sections Robb T. Koether. Hampden-Sydney College. Wed, Feb 1, 2017

Basic CSS Lecture 17

Views. Lecture 15 Section 5.3. Robb T. Koether. Hampden-Sydney College. Mon, Feb 18, 2013

The Traveling Salesman Problem Cheapest-Link Algorithm

Introduction to Compiler Design

The Mesh Class. Lecture 26. Robb T. Koether. Wed, Oct 28, Hampden-Sydney College

Informatics 1: Data & Analysis

Functional Dependencies and Normal Forms

Transcription:

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

1 XPath 2 Executing XPath Expressions 3 XPath Expressions 4 Predicates 5 Axes 6 Assignment Robb T. Koether (Hampden-Sydney College) XPath Wed, Apr 16, 2014 2 / 28

Outline 1 XPath 2 Executing XPath Expressions 3 XPath Expressions 4 Predicates 5 Axes 6 Assignment Robb T. Koether (Hampden-Sydney College) XPath Wed, Apr 16, 2014 3 / 28

XPath XPath is a method of writing expressions that will navigate an XML document to extract the desired information. XPath expressions describe paths through the XML tree. Robb T. Koether (Hampden-Sydney College) XPath Wed, Apr 16, 2014 4 / 28

XPath Nodes XPath expressions search for matching nodes. There are several types of node in an XML document. Element nodes Attribute nodes Text nodes Document node Comment nodes Instruction nodes Namespace nodes Robb T. Koether (Hampden-Sydney College) XPath Wed, Apr 16, 2014 5 / 28

Outline 1 XPath 2 Executing XPath Expressions 3 XPath Expressions 4 Predicates 5 Axes 6 Assignment Robb T. Koether (Hampden-Sydney College) XPath Wed, Apr 16, 2014 6 / 28

Executing XPath Expressions When an XPath expression is executed, the result is a list of all values that match the expression. The list could be a long string of text or it could a sequence of elements, depending on the expression. Robb T. Koether (Hampden-Sydney College) XPath Wed, Apr 16, 2014 7 / 28

Executing XPath Expressions One way to run XPath is to download Saxon-HE from the Saxon website: http://saxon.sourceforge.net/ It includes the executable Query.exe. Then run Query.exe from the command line: >Query query-file The query-file will open the XML file and process it. The output will appear in the command window, or it can be redirected to a file. It is also possible to have the XML file invoke the XPath expression on itself in a browser. Robb T. Koether (Hampden-Sydney College) XPath Wed, Apr 16, 2014 8 / 28

Outline 1 XPath 2 Executing XPath Expressions 3 XPath Expressions 4 Predicates 5 Axes 6 Assignment Robb T. Koether (Hampden-Sydney College) XPath Wed, Apr 16, 2014 9 / 28

XPath Expressions The Root Node doc("library.xml")/library XPath expressions begin with doc("file-name"); If the root node is named library, then the above expression matches the entire XML document, beginning at the root element library. Robb T. Koether (Hampden-Sydney College) XPath Wed, Apr 16, 2014 10 / 28

XPath Expressions Navigating Down the Tree doc("library.xml")/library/books/book We may move any number of levels down the tree by naming the elements. The value of the expression is a list of all elements (including their contents) that match the expression. The above expression matches all book elements that are children of books elements that are children of the library element. Try out various paths with the library database. Robb T. Koether (Hampden-Sydney College) XPath Wed, Apr 16, 2014 11 / 28

XPath Expressions The Double Slash doc("library.xml")//author The double slash // means any number of levels down. The above expression matches author elements at any level in the document. Robb T. Koether (Hampden-Sydney College) XPath Wed, Apr 16, 2014 12 / 28

XPath Expressions The Wildcard doc("library.xml")//author/* The asterisk * is a wildcard that means any child. The above expression matches all child elements of author elements. Robb T. Koether (Hampden-Sydney College) XPath Wed, Apr 16, 2014 13 / 28

XPath Expressions The Or Operator doc("library.xml")//(fname lname) The vertical stroke means or. We may use it to match more than one type of element. The above expression matches fname and lname elements. Robb T. Koether (Hampden-Sydney College) XPath Wed, Apr 16, 2014 14 / 28

XPath Expressions The Current Node doc("library.xml")//author/. doc("library.xml")//author The dot. means the current node. The two expressions above have the same value. The current node is called the context node. Robb T. Koether (Hampden-Sydney College) XPath Wed, Apr 16, 2014 15 / 28

XPath Expressions The Current Node doc("library.xml")//author/lname doc("library.xml")//author/./lname These two expressions also have the same value. Robb T. Koether (Hampden-Sydney College) XPath Wed, Apr 16, 2014 16 / 28

XPath Expressions The Parent Node doc("library.xml")//author/../title Two dots.. means the parent node. The above expression will match the title elements of every book, collection, or volume with an author element. Robb T. Koether (Hampden-Sydney College) XPath Wed, Apr 16, 2014 17 / 28

Outline 1 XPath 2 Executing XPath Expressions 3 XPath Expressions 4 Predicates 5 Axes 6 Assignment Robb T. Koether (Hampden-Sydney College) XPath Wed, Apr 16, 2014 18 / 28

XPath Predicates Predicates... node[predicate] A predicate is a statement that may be true or false. In an XPath expression, we may include predicates at any level. The predicate is written in square brackets. The predicate is applied to the children of the context node. The XPath expression will match elements in the expression for which the predicate is true. Robb T. Koether (Hampden-Sydney College) XPath Wed, Apr 16, 2014 19 / 28

XPath Predicates The Parent Node doc("library.xml")//book[genre] doc("library.xml")//book[pages < 400]/title The first expression will match all book elements of books that have a genre. The second expression will match the title elements of books with less than 400 pages. Robb T. Koether (Hampden-Sydney College) XPath Wed, Apr 16, 2014 20 / 28

XPath Predicates Write XPath expressions that will match the following. The first and last names of all authors. All last names of the authors of books that have a genre. All books published before 1930. All titles of volumes in the Fiction genre. All titles of books, volumes, or collections in the Fiction genre. Robb T. Koether (Hampden-Sydney College) XPath Wed, Apr 16, 2014 21 / 28

Outline 1 XPath 2 Executing XPath Expressions 3 XPath Expressions 4 Predicates 5 Axes 6 Assignment Robb T. Koether (Hampden-Sydney College) XPath Wed, Apr 16, 2014 22 / 28

XPath Axes An axis is an expression that helps navigate through the XML tree. Examples are. and.. The following axes are available. self child parent ancestor descendant preceding-sibling following-sibling The axis is always relative to the context node. Robb T. Koether (Hampden-Sydney College) XPath Wed, Apr 16, 2014 23 / 28

XPath Axes XPath Axes axis-name node-name predicates The axis name is followed by :: The default axis is child:: Robb T. Koether (Hampden-Sydney College) XPath Wed, Apr 16, 2014 24 / 28

XPath Axes The parent Axis doc("library.xml")//volumes/parent::collection [genre="fiction"]//lname The above expression will match the last names (of authors) of volumes in collections of the Fiction genre. Robb T. Koether (Hampden-Sydney College) XPath Wed, Apr 16, 2014 25 / 28

XPath Axes The parent Axis doc("library.xml")//lname/ancestor::books doc("library.xml")//lname[ancestor::books] doc("library.xml")//title/..[descendant::mname] doc("library.xml")//book[title="the Deerslayer"] /preceding-sibling::book/title What will these expressions produce? Robb T. Koether (Hampden-Sydney College) XPath Wed, Apr 16, 2014 26 / 28

Outline 1 XPath 2 Executing XPath Expressions 3 XPath Expressions 4 Predicates 5 Axes 6 Assignment Robb T. Koether (Hampden-Sydney College) XPath Wed, Apr 16, 2014 27 / 28

Assignment Assignment Visit the W3Schools websites http://www.w3schools.com/xpath/ Visit the sections labeled XPath HOME through XPath Summary. Robb T. Koether (Hampden-Sydney College) XPath Wed, Apr 16, 2014 28 / 28