August 20061 Chapter 6 - XPath & XPointer Learning XML by Erik T. Ray Slides were developed by Jack Davis College of Information Science and Technology.

Slides:



Advertisements
Similar presentations
XML-XSL Introduction SHIJU RAJAN SHIJU RAJAN Outline Brief Overview Brief Overview What is XML? What is XML? Well Formed XML Well Formed XML Tag Name.
Advertisements

Dr. Alexandra I. Cristea CS 253: Topics in Database Systems: XPath, NameSpaces.
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.
XML: Extensible Markup Language
Internet Technologies1 1 Lecture 4: Programming with XSLT.
1 XSLT – eXtensible Stylesheet Language Transformations Modified Slides from Dr. Sagiv.
Managing Data Exchange: XPath
XPath XML Path Language. Outline XML Path Language (XPath) Data Model Description Node values XPath expressions Relative expressions Simple subset of.
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.
Lecture 13. The various node tests also work on this axis: eg node() This book has descendant-or- self nodes As expected, text nodes are included in the.
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.
XSL Concepts Lecture 7. XML Display Options What can XSL Transformations do? generation of constant text suppression of content moving text (e.g., exchanging.
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.
Manohar – Why XML is Required Problem: We want to save the data and retrieve it further or to transfer over the network. This.
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
10/06/041 XSLT: crash course or Programming Language Design Principle XSLT-intro.ppt 10, Jun, 2004.
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.
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.
Introduction to XPath Web Engineering, SS 2007 Tomáš Pitner.
CSE3201/CSE4500 Information Retrieval Systems
XP New Perspectives on XML Tutorial 6 1 TUTORIAL 6 XSLT Tutorial – Carey ISBN
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
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.
August Chapter 2 - Markup and Core Concepts Learning XML by Erik T. Ray Slides were developed by Jack Davis College of Information Science and Technology.
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.
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.
ECA 228 Internet/Intranet Design I XSLT Example. ECA 228 Internet/Intranet Design I 2 CSS Limitations cannot modify content cannot insert additional text.
XSLT Kanda Runapongsa Dept. of Computer Engineering Khon Kaen University.
Database Systems Part VII: XML Querying Software School of Hunan University
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.
XSLT Streaming Terminology Understanding “Climbing” Roger L. Costello January 29, 2014.
XP New Perspectives on XML, 2 nd Edition Tutorial 8 1 TUTORIAL 8 CREATING ELEMENT GROUPS.
1 XML Data Management XPath Principles Werner Nutt.
More XML XPATH, XSLT CS 431 – February 23, 2005 Carl Lagoze – Cornell University.
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.
XPath --XML Path Language Motivation of XPath Data Model and Data Types Node Types Location Steps Functions XPath 2.0 Additional Functionality and its.
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:
SEMI-STRUCTURED DATA (XML) 1. SEMI-STRUCTURED DATA ER, Relational, ODL data models are all based on schema Structure of data is rigid and known is advance.
© 2013 The MITRE Corporation. All rights reserved. XSLT Streaming Terminology Understanding “Climbing” Roger L. Costello, February 3, 2014.
XML Extensible Markup Language
CITA 330 Section 5 XPath. XSL XSL (Extensible Stylesheet Language) is the standard language for writing stylesheets to transform XML documents among different.
5 Copyright © 2004, Oracle. All rights reserved. Navigating XML Documents by Using XPath.
XML Schema – XSLT Week 8 Web site:
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.
Unit 4 Representing Web Data: XML
Chapter 7 Representing Web Data: XML
XML Path Language Andy Clark 17 Apr 2002.
XPath 9-May-19.
More XML XML schema, XPATH, XSLT
XPath 7-Dec-19.
Presentation transcript:

August Chapter 6 - XPath & XPointer Learning XML by Erik T. Ray Slides were developed by Jack Davis College of Information Science and Technology Radford University

August XPath XML is often compared to a database because of the way it structures information for easy retrieval. With a little knowledge of the markup language, you can locate and extract any piece of information. XPath is used to locate a specific data element from a known location within a document and it can be used to provide contextual details to a processing program. For example, one could specify that items in a list should use a particular kind of bullet specified in a metadata section at the beginning of the document. Every XML document can be represented graphically as a tree structure. Because there is only one possible tree configuration for any given document, there is a unique path from the root to any other point. XPath describes how to climb the tree in a series of steps.

August XML Trees Each step in a path touches a branching or terminal point in the tree called a node (remember these are the elements). A terminal node is called a leaf (no descendants). There are seven different kinds of nodes: - root The root of the document is a special kind of node. It's not an element, but rather it contains the document element. It also contains any comments or processing instructions that surround the document element. - element Elements and the root node share a special property among nodes: they alone can contain other nodes. An element node can contain other elements. In a tree, this is the point where branches meet. Empty elements are leaf nodes.

August XML Trees (cont.) - attribute XPath treats attributes as separate nodes from their element hosts. This allows you to select the element as a whole or the only the attribute in that element using the same path syntax. An attribute is like an element that contains only text. - text A region of uninterrupted text is treated as a leaf node. It is always the child of an element. An element may have more than one text node cheld, however, if it is broken up by elements or other node types. Keep in mind, if you process text in an element: you may have to check more than one node. - comment An XML comment is considered a valid node. - processing instruction Like comments, a processing instruction can appear anywhere in the document under the root.

August XML Trees (cont.) Namespace A namespace is actually a region of the document not just the possession of a single element. All the descendants of that element will be affected. XML processors must pay special attention to namespaces, so XPath makes it a unique node type. The DTD is not included in the list of nodes. XPath maintains the structure and content of a document so that document could be reconstructed almost exactly. (The order of the attributes might change, but since order of attributes is not significant in XML, a semantically equivalent document can be produced. In XML any node in the tree can be thought of as a tree in its own right (subtree). Trees facilitate recursive programming. XSLT is elegant because a rule treats every element as a tree.

August Finding Nodes XPath uses chains of steps called a location path to define the location of elements in an XML tree. A location step has three parts: - an axis that describes the direction to travel, - a node test that specifies what kinds of nodes' - and a set of optional predicates that use Boolean tests to reduce the candidates. The axis is a keyword that specifies a direction you can travel from any node. You can go up through ancestors, down through descendants, or linearly through siblings.

August Node Axes Axis TypesMatches Ancestor All nodes above the context node, including the parent, grandparent, and so on up to the root node. Ancestor-or -Self The ancestor node plus the context node. Attribute Attributes of the context node. Child Children of the context node. Descendent Children of the context node, plus their children, and so on down to the leaves of the subtree. Descendant- or-self The descendant node plus the context node.

August Node Axes (cont.) Axis TypesMatches Following Nodes that follow the context node at any level in the document. Does not include any descendants but does include following siblings and their descendants. Following-sibling Nodes that follow the context node at the same level. Namespace All the namespace nodes of an element. Parent The parent of the context node. Preceding Nodes that occur before the context node at any level. Does not include descendents but does include preceding siblings and their descendants Preceding-sibling Nodes that occur before the context node at the same level. Self The context node.

August Node Axes After the axis comes a node test parameter, joined to the axis by a double colon (::). A name can be used in place of an explicit node type, in which case the node type is inferred from the axis. For the attribute axis - attribute, namespace axis - namespace, all other axes the node is assumed to be an element. In the absence of a node axis specifier, the axis is assumed to be child and the node is assumed to be of type element.

August Node tests TermMatches /The root node: the node containing the root element and any comments or processing instructions that precede it node()matches any node, attribute::node() - would select all the attributes of the context node *attribute axis - any attribute, namespace axis - any namespace others - any element crabcakeattribute axis - the attribute named crabcake of the context node, (same for namespace & elements) text()any text node processing- instruction() any processing instruction processing- instruction('for- web') any processing instruction with target for-web comment()any comment node

August Location Paths Location path steps are chained together using the slash (/) character. Each step gets you a little closer to the node you want to locate. It's like giving directions. For example, to get from the root node to a para element inside a section inside a chapter inside a book, a path might look like this: book/chapter/section/para XPath defines some handy matches an attribute named role. the context node. /* matches the document element. Any path that starts with a / is an absolute path, the next step is * which matches any element parent::*/following-sibling::para matches all paras that follow the parent of the context node.

August Location Paths (cont.).. matches the parent node. The double dot is shorthand for parent::node().//para matches any element of type para that is a descendent of the current node. The // is shorthand for /descendant-or-self::node() //para matches any para descending from the root node. It matches all paras anywhere in the document. A location path starting with a // is assumed to begin at the root.../* matches all sibling elements (and the context node if it is an element)

August Examples Look at the document example in 6-1 which is a sample XML document.example in 6-1 Here's some location path examples /quotelist/child::node() matches all the quotation elements plus the XML comment /quotelist/quotation matches all the quotation elements /*/* matches all the quotation elements matches the style attribute of the last quotation element id('q2')/.. matches the document element

August Predicates If the axis and node type aren't sufficient to narrow down the selection, you can use one or more predicates (Boolean expressions). Every node that passes this test (in addition to the node test and axis specifier) is included in the final node set. Nodes that fail the test are not. Examples text element in the third quotation element. /*/*[position()=last()] last quotation element. The position() function equals the position of the most recent step among eligible candidates. The function last() is equal to the total number of candidates (in this case 5) The first, third, and fourth quotation elements. The or keyword is a Boolean op.

August Boolean Expressions XPath contains a full set of comparison operators to compare strings or numbers. There are also node set expressions. The expression evaluates to a set of nodes. This is a set in the strict mathematical sense, meaning that it contains no duplicates. The same node can be added many times, but the set will always contain only one copy of it. Node Set functions count (node set) returns the no. of nodes generate-id(node set) string containing a unique identifier for the first node in node set, or for the context node if the argument is left out. This string is generated by the processor and guaranteed to be unique for each node. last() the number of the node in the context node set

August Node Set Functions (cont.) local-name(node set) name of the first node in node set, without the namespace prefix. name (node set) name of the first node in node set including the namespace prefix namespace-url(node set) the URI of the namespace for the first node in node set, without an argument it returns the namespace URI for the context node. position() the number of the context node in the context node set. There are also functions that create node sets, pulling together nodes from all over the document.