XPath --XML Path Language Motivation of XPath Data Model and Data Types Node Types Location Steps Functions XPath 2.0 Additional Functionality and its.

Slides:



Advertisements
Similar presentations
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.
Advertisements

Internet Technologies1 1 Lecture 4: Programming with XSLT.
XPath XML Path Language. Outline XML Path Language (XPath) Data Model Description Node values XPath expressions Relative expressions Simple subset of.
Transforming XML Part I Document Navigation with XPath John Arnett, MSc Standards Modeller Information and Statistics Division NHSScotland Tel:
The learning site: /xpath_syntax.asp xsl/xsl/slides.html.
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.
XML 6.6 XPath 6. What is XPath? XPath is a syntax used for selecting parts of an XML document The way XPath describes paths to elements is similar to.
2-Jun-15 XPath. 2 What is XPath? XPath is a syntax used for selecting parts of an XML document The way XPath describes paths to elements is similar to.
XPath s/xmljava/chapters/ch16.html.
Introduction to XLink Transparency No. 1 XML Information Set W3C Recommendation 24 October 2001 (1stEdition) 4 February 2004 (2ndEdition) Cheng-Chia Chen.
XPath Carissa Mills Jill Kerschbaum. What is XPath? n A language designed to be used by both XSL Transformations (XSLT) and XPointer. n Provides common.
Lecture 12. Default Processing in XSLT The default processing in XSLT is to process the XPath root node The default processing for various node types.
XML Language Family Detailed Examples Most information contained in these slide comes from: These slides are intended.
XPath Tao Wan March 04, What is XPath? n A language designed to be used by XSL Transformations (XSLT), Xlink, Xpointer and XML Query. n Primary.
XML –Query Languages, Extracting from Relational Databases ADVANCED DATABASES Khawaja Mohiuddin Assistant Professor Department of Computer Sciences Bahria.
September 15, 2003Houssam Haitof1 XSL Transformation Houssam Haitof.
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.
XP ATH - XML Path Language. W HAT IS XP ATH ? XPath, the XML Path Language, is a query language for selecting nodes from an XML document.query languagenodesXML.
SD2520 Databases using XML and JQuery
XSLT Brent P. Christie Major USMC. XSLT Overview  What is XSLT? –XSL is the Extensible Style Language. –It has two parts: the transformation language.
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.
CSE3201/CSE4500 XPath. 2 XPath A locator for elements or attributes in an XML document. XPath expression gives direction.
TDDD43 XML and RDF Slides based on slides by Lena Strömbäck and Fang Wei-Kleiner 1.
SDPL 20075: Overview of XSLT1 5 Document Transformations n XSLT (1.0 W3C Rec. 11/1999; XSLT 2.0 Rec. 1/07) –A language for transforming XML documents –initial.
1/17 ITApplications XML Module Session 7: Introduction to XPath.
Introduction to XPath Web Engineering, SS 2007 Tomáš Pitner.
XML DOCUMENTS & DATABASES. Summary of Introduction to XML HTML vs. XML HTML vs. XML Types of Data Types of Data Basics of XML Basics of XML XML Syntax,
CSE3201/CSE4500 Information Retrieval Systems
XP New Perspectives on XML Tutorial 6 1 TUTORIAL 6 XSLT Tutorial – Carey ISBN
XSLT and XPath, by Dr. Khalil1 XSL, XSLT and XPath Dr. Awad Khalil Computer Science Department AUC.
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 Language Family Detailed Examples Most information contained in these slide comes from: These slides are intended.
1 XPath XPath became a W3C Recommendation 16. November 1999 XPath is a language for finding information in an XML document XPath is used to navigate through.
1 CIS336 Website design, implementation and management (also Semester 2 of CIS219, CIS221 and IT226) Lecture 6 XSLT (Based on Møller and Schwartzbach,
Representing Web Data: XML CSI 3140 WWW Structures, Techniques and Standards.
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.
XPath Kanda Runapongsa Dept. of Computer Engineering Khon Kaen University.
Processing of structured documents Spring 2003, Part 7 Helena Ahonen-Myka.
XPath. Why XPath? Common syntax, semantics for [XSLT] [XPointer][XSLT] [XPointer] Used to address parts of an XML document Provides basic facilities for.
XSLT part of XSL (Extensible Stylesheet Language) –includes also XPath and XSL Formatting Objects used to transform an XML document into: –another XML.
XSLT Kanda Runapongsa Dept. of Computer Engineering Khon Kaen University.
More on XSLT 07. More on XSLT © Aptech Limited XPath  In this first lesson, XPath, you will learn to:  Define and describe XPath.  Identify nodes according.
IS432: Semi-Structured Data Dr. Azeddine Chikh. 6. XML Path (XPath)
VICTORIA UNIVERSITY OF WELLINGTON Te Whare Wananga o te Upoko o te Ika a Maui SWEN 432 Advanced Database Design and Implementation Query Data Model Lecturer.
August Chapter 6 - XPath & XPointer Learning XML by Erik T. Ray Slides were developed by Jack Davis College of Information Science and Technology.
XPath Aug ’10 – Dec ‘10. XPath   XML Path Language   Technology that allows to select a part or parts of an XML document to process   XPath was.
SDPL 2001Notes 5: XSLT1 5. Document Transformations n XSLT (W3C Rec. Nov-99) –A language for transforming XML documents »representative of features common.
XPath Presented by Kushan Athukorala. 2 Agenda XPath XPath Terminology Selecting Nodes Predicates.
1 XML Data Management XPath Principles Werner Nutt.
XP New Perspectives on XML, 2 nd Edition Tutorial 7 1 TUTORIAL 7 CREATING A COMPUTATIONAL STYLESHEET.
Session II Chapter 3 – Chapter 3 – XPath Patterns & Expressions Chapter 4 – XPath Functions Chapter 15 – XPath 2.0http://
University of Nottingham School of Computer Science & Information Technology Introduction to XML 2. XSLT Tim Brailsford.
CSE3201/CSE4500 XPath. 2 XPath A locator for items in XML document. XPath expression gives direction of navigation.
1 XPath. 2 Agenda XPath Introduction XPath Nodes XPath Syntax XPath Operators XPath Q&A.
1 The XPath Language. 2 XPath Expressions Flexible notation for navigating around trees A basic technology that is widely used uniqueness and scope in.
Jackson, Web Technologies: A Computer Science Perspective, © 2007 Prentice-Hall, Inc. All rights reserved Chapter 7 Representing Web Data:
CITA 330 Section 5 XPath. XSL XSL (Extensible Stylesheet Language) is the standard language for writing stylesheets to transform XML documents among different.
Displaying Data with XSLT ©NIITeXtensible Markup Language/Lesson 6/Slide 1 of 45 Objectives In this lesson, you will learn to: * Perform conditional formatting.
5 Copyright © 2004, Oracle. All rights reserved. Navigating XML Documents by Using XPath.
Unit 4 Representing Web Data: XML
Beginning XML 4th Edition.
Querying and Transforming XML Data
{ XML Technologies } BY: DR. M’HAMED MATAOUI
Chapter 7 Representing Web Data: XML
XML Path Language Andy Clark 17 Apr 2002.
XML DOCUMENTS & DATABASES
Presentation transcript:

XPath --XML Path Language Motivation of XPath Data Model and Data Types Node Types Location Steps Functions XPath 2.0 Additional Functionality and its difference with XPath 1.0 XPath 1.0

Motivation A desire to provide common syntax and semantics for functionality shared between XSLT and XPointer. Primary purpose: navigation within a document Also Provide basic facilities for manipulation of strings, numbers and booleans. Current version: XPath 2.0. But XPath 1.0 is the more widely- used version.

Data Model XPath models an XML document as a tree of nodes.

John Doe /gallery/photographer

Inside XML expressions… Expression == a path through the document Made from:  Nodes  Variables (hold values)  Functions  Return values (one of the four XPath data types)

XML Data Types Numbers String Booleans Node-set

The Number Data Type A floating-point number Special number value: NaN Numeric operators: +addition -subtraction Needs to be preceded by whitespace *multiplication divdivision modremainder Same as % in Java

The String Data Type A sequence of characters A single character in XPath corresponds to a single Unicode abstract character rather than standard Unicode values

The Boolean Data Type Values: true, false An or expression An and expression Equality and relational expression: =, !=, =, > (would be complex if node-sets are involved)

=, !=, =, > 1.Neither object to be compared is a node-set and the operator is = and != Different types  Convert to common types: If one operand is boolean, convert the other to boolean. Otherwise, if one operand is number, convert the other to number. Otherwise, if one operand is string, convert the other to string.

=, !=, =, > 2.Neither object to be compared is a node-set and the operator is, >= convert both objects to numbers and compare the numbers according to IEEE754 Numbers are compared for equality according to IEEE754. Two booleans are equal if either both are true or both are false. Two strings are equal if and only if they consist of the same sequence of UCS characters.

=, !=, =, > 3.If node-set is involved How to compare? – Both are node-sets  string-values of two nodes – The other is a number  convert string-value of that node to number using number function – The other is a string  string-value of that node and the string – The other is a boolean  convert that node to boolean using boolean function

Node Types The XPath tree contains nodes. There are seven types of node:  root nodes  Element nodes  Text nodes  Attribute nodes  Namespace nodes  Processing instruction nodes  Comment nodes Document order orders element nodes in order of the occurrence of their start-tag in the XML

Root Node and Element Nodes Root node: root of the tree The string-value of root node is the concatenation of the string- values of all its text node descendants in document order Element node: there is one for every element in the document The string-value: same as root node Unique IDs: An element node may have a unique identifier. This is the value of the attribute that is declared in the DTD as type ID.

Example: Root Node and Element Nodes Mercury

Attribute Nodes  Each element node (parent) has an associated set of attribute nodes (not child node of its parent element)  An element has attribute nodes only for attributes explicitly specified in the start-tag or empty-element tag of that element or explicitly declared in DTD.  At the end of your XPath expression, which is normally the element you want to select, add the at sign plus the name of the attribute you wish to select.

Example: Attribute Nodes Mercury

Namespace Nodes Each element has an associated set of namespace nodes, one for each distinct namespace prefix that is in scope for the element and one for the default namespace if one is in scope for the element.

Example: Namespace Nodes Mercury

Processing Instruction Nodes and Comment Nodes There is a processing instruction node/comment node for every processing instruction/comment, except for any processing instruction/comment that occurs within the document type declaration. String-values:  Processing Instruction Nodes: not include terminating ?>  Comment Nodes: not include

Example: Processing and Comment Nodes Mercury

Text Nodes Character data is grouped into text nodes. Each character within a CDATA section is treated as character data.  Example: in the source document will result in a single < character in a text node in the tree.

Example: Text Nodes Mercury

Location Paths  To tell XPath software exactly where and what data to extract from an XML document.  A location path consists of one or more location steps, separated by / or //.  In Xpath, the location path can combine with the | or “pipe” character. Complete version /child::planets/child::planet/child::name[2]/text() Abbreviated version /planets/planet/name[2]/text()

Location Step Each location step is made up of an axis, a node test, and zero or more predicates. axis :: node-test [predicate] Example child :: name [position() = 2] select child nodes element second element

XPath 1.0 Axes Each XPath location step must specify an axis. Defines a node set relative to the current node. Default axis is the child axis. There are 13 XPath axes for version 1.0.

Example: Using ancestor axis Mercury Venus Earth location path: /planet/day/ancestor::planet Results: Mercury Venus Earth

Example: Using ancestor-or-self axis Mercury Venus Earth location path: /planet/day/ancestor-or-self::* Results: planets planet day planets planet planets

Example: Using descendant axis Mercury Venus Earth location path: //planet/descendant::* Results: planet name mass day radius density distance

Example: Using parent axis Mercury Venus Earth location path: //day/parent::* Results: planet planet planet

Example: Using following-sibling axis Mercury Venus Earth location path: /planets/planet[1]/mass/following-sibling::* Results: day radius density distance

Example: Using namespace axis Mercury Venus location path: namespace::* Results:

Example: Using parent axis Mercury Venus Earth location path: //day/parent::* Results: planet planet planet

XPath 1.0 Abbreviated Syntax There are a number of abbreviations in XPath syntax. – self::node() can be written as. – parent::node() can be written as.. – child::nodename can be written as nodename – attribute::nodename can be written – /descendant-or-self::node()/ can be written as //

XPath 1.0 Node Tests Node test tells XPath which of the nodes in the document are needed. Types of node tests, – * wildcard character matches any element or attribute name. – Name matches a node with that name. – comment() node test selects comment nodes. – node() selects any type of node. – processing-instruction() node test selects a processing instruction node. – text() selects a text node.

XPath 1.0 Predicates A location step has zero or more predicates. Predicate gives more information about the nodes or nodes needed. Able to use built-in XPath functions in predicates.

XPath 1.0 Boolean Functions Boolean functions convert argument into boolean value. boolean function return boolean value. false function return false value not function reverse boolean value

XPath 1.0 Numeric Functions XPath 1.0 has several numeric functions that operate on numbers. number function ceiling function return the smallest integer sum function add together the numeric values.

XPath 1.0 String Functions XPath 1.0 has many string functions. concat (join all strings together.) contains (check if first string contains second string) normalize-space (remove leading and trailing whitespace and multiple consecutive whitespace is replaced with a single space)

XPath 1.0 Node-Set Operators and Functions XPath 1.0 have few operators and functions to work on the node-sets. / and // operators used to create the location paths. count function return the number of nodes in node-set. position function return the position of the context node in the node-set.

XPath 2.0 Was published as a W3C Recommendation on January 23, It represents an increase in the size and capability of he XPath language. It supports atomic types(a single atomic value is regarded a sequence of length one), defined a built-in types in XML schema Xpath 1.0 node-sets are replaced by node- sequences, which may be in order

Version 2.0 also offers a greatly expanded set of functions and operators XPath 2.0 is in fact a subset of XQuery 1.0. It offers a for expression which is cut-down version of the “FLOWR" expressions in XQuery. It is possible to describe the language by listing the parts of XQuery that it leaves out: the main examples are the query prolog, element and attribute constructors, the remainder of the "FLWOR" syntax, and the typeswitchexpression.