{ XML Technologies } BY: DR. M’HAMED MATAOUI

Slides:



Advertisements
Similar presentations
Dr. Alexandra I. Cristea CS 253: Topics in Database Systems: XPath, NameSpaces.
Advertisements

XML: Extensible Markup Language
Dr. Alexandra I. Cristea XPath and Namespaces.
1 XQuery Web and Database Management System. 2 XQuery XQuery is to XML what SQL is to database tables XQuery is designed to query XML data What is XQuery?
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.
1 COS 425: Database and Information Management Systems XML and information exchange.
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.
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.
Cornell CS 502 More XML XML schema, XPATH, XSLT CS 502 – Carl Lagoze – Cornell University.
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.
SD2520 Databases using XML and JQuery
Xpath Sources:
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.
Lecture 7 of Advanced Databases XML Querying & Transformation Instructor: Mr.Ahmed Al Astal.
Lecture 6 of Advanced Databases XML Schema, Querying & Transformation Instructor: Mr.Ahmed Al Astal.
XML for E-commerce III Helena Ahonen-Myka. In this part... n Transforming XML n Traversing XML n Web publishing frameworks.
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.
Java WWW Week 10 Version 2.1 Mar 2008 Slide Java (JSP) and XML  Format of lecture: What is XML? A sample XML file… How to use.
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
Lecture 6 of Advanced Databases XML Querying & Transformation Instructor: Mr.Eyad Almassri.
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.
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.
Representing Web Data: XML CSI 3140 WWW Structures, Techniques and Standards.
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.
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.
[ Part III of The XML seminar ] Presenter: Xiaogeng Zhao A Introduction of XQL.
XPath Presented by Kushan Athukorala. 2 Agenda XPath XPath Terminology Selecting Nodes Predicates.
CS 157B: Database Management Systems II February 11 Class Meeting Department of Computer Science San Jose State University Spring 2013 Instructor: Ron.
1 XML Data Management XPath Principles Werner Nutt.
1 JAXP & XPATH. Objectives 2  XPath  JAXP Processing of XPath  Workshops.
CS 157B: Database Management Systems II February 13 Class Meeting Department of Computer Science San Jose State University Spring 2013 Instructor: Ron.
XML Query: xQuery Reference: Xquery By Priscilla Walmsley, Published by O’Reilly.
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://
Martin Kruliš by Martin Kruliš (v1.1)1.
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.
USING ANDROID WITH THE DOM. Slide 2 Lecture Summary DOM concepts SAX vs DOM parsers Parsing HTTP results The Android DOM implementation.
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. Contents  Parsing an XML Document  Validating XML Documents.
{ XML Technologies } BY: DR. M’HAMED MATAOUI
XML and XPath.
Xpath creation.
Querying and Transforming XML Data
XML in Web Technologies
XML Path Language Andy Clark 17 Apr 2002.
Querying XML XPath.
Querying XML XPath.
Modified Slides from Dr. Sagiv
Modified Slides from Dr. Sagiv
XPath 9-May-19.
More XML XML schema, XPATH, XSLT
XML DOCUMENTS & DATABASES
Xpath October 16, 2019 ICS 541: Xpath.
WaysInJavaToParseXML
XPath 7-Dec-19.
Presentation transcript:

{ XML Technologies } BY: DR. M’HAMED MATAOUI Chapter V: Addressing and Querying XML Documents

Overview of Presentation Introduction to XML Technologies Fundamental Concepts of XML XML Grammars (DTD, W3C schema) XML document transformations (CSS, XSLT) Addressing and Querying XML Documents XPath XQuery Processing XML (DOM & SAX) Overview of Presentation [ Dr. M’hamed MATAOUI ]

Goals Learn how to address (navigate) XML elements by using XPath Notation. Understand and Use XQuery language for querying XML data Goals [ Dr. M’hamed MATAOUI ]

XPath XPath is a syntax for defining parts of an XML document XPath (XML Path Language) is a query language for selecting nodes from an XML document. In addition, XPath may be used to compute values (e.g., strings, numbers, or Boolean values) from the content of an XML document. XPath was defined by the World Wide Web Consortium (W3C). XPath is used primarily for selecting parts of an XML document. For this purpose the XML document is modelled as a tree of nodes. XPath allows nodes to be selected by means of a hierarchic navigation path through the document tree. XPath is a syntax for defining parts of an XML document XPath uses path expressions to navigate in XML documents XPath contains a library of standard functions XPath is a major element in the XSLT standard XPath is a W3C recommendation From : Wikipedia From : http://www.w3schools.com/ XPath [ Dr. M’hamed MATAOUI ]

XPath XPath Path Expressions XPath XPath uses path expressions to select nodes or node-sets in an XML document. These path expressions look very much like the expressions used in a traditional computer file system: Example: /BOOKS/BOOK/AUTHOR/LASTNAME In general, an XPath expression specifies a pattern that selects a set of XML nodes. (from : docs.oracle.com) From : http://www.w3schools.com/ XPath [ Dr. M’hamed MATAOUI ]

XPath XPath XPath Standard Functions XPath includes over 100 built-in functions: string values, numeric values, booleans, date and time comparison, node manipulation, sequence manipulation, and much more. Today XPath expressions can also be used in JavaScript, Java, XML Schema, PHP, Python, C and C++, and lots of other languages. XPath is Used in XSLT XPath is a major element in the XSLT standard. With XPath knowledge you will be able to take great advantage of your XSLT knowledges. XPath and XQuery 3.0 XPath is a major element in the XSLT standard. With XPath knowledge you will be able to take great advantage of your XSLT knowledges. From : http://www.w3schools.com/ XPath [ Dr. M’hamed MATAOUI ]

XPath XPath Nodes The nodes in an XPath expression refer to more than just elements. They also refer to text and attributes, among other things. In fact, the XPath specification defines an abstract document model that defines seven kinds of nodes: Root Element Text Attribute Comment Processing instruction Namespace XPath [ Dr. M’hamed MATAOUI ]

XPath XPath Relationship of Nodes Parent Each element and attribute has one (and only one) parent. Children Element nodes may have zero, one or more children. Siblings Nodes that have the same parent. Ancestors A node's parent, parent's parent, etc. Descendants A node's children, children's children, etc. XPath [ Dr. M’hamed MATAOUI ]

XPath XPath Syntax XPath uses path expressions to select nodes or node-sets in an XML document. The node is selected by following a path or steps. The most useful path expressions are: Note: If the path starts with a slash ( / ) it always represents an absolute path to an element! XPath [ Dr. M’hamed MATAOUI ]

XPath XPath [ Dr. M’hamed MATAOUI ]

XPath XPath Select Node by indicating it’s « Index » [ Dr. M’hamed MATAOUI ]

XPath XPath [ Dr. M’hamed MATAOUI ]

XPath OR XPath [ Dr. M’hamed MATAOUI ]

XPath XPath [ Dr. M’hamed MATAOUI ]

XPath XPath [ Dr. M’hamed MATAOUI ]

XPath XPath [ Dr. M’hamed MATAOUI ]

XPath Reaching unknown nodes Predicates XPath wildcards can be used to select unknown XML elements. Predicates are used to find a specific node or a node that contains a specific value. Predicates are always embedded in square brackets. Wildcards = Caractères génériques XPath [ Dr. M’hamed MATAOUI ]

XPath XPath Operators Operator Meaning [] predicate /, // child nodes, descendant nodes | union *, div, mod multiply, divide, modulo +, - plus, minus <, <=;, >, >=; Less-than, less-or-equal, greater-than, greater-or-equal = equals and Boolean and or Boolean or XPath Operators XPath [ Dr. M’hamed MATAOUI ]

XPath An XPath expression returns either a node-set, a string, a Boolean, or a number. XPath Operators XPath [ Dr. M’hamed MATAOUI ]

XPath XPath Axes An axis defines a node-set relative to the current node. XPath [ Dr. M’hamed MATAOUI ]

following is not following-sibling XPath Examples: /course/plan/ancestor::node()/Lecturer /course/plan/ancestor-or-self::node() /course/Lecturer/attribute::* /course/child::node()/comment() /course/descendant::node()[4]/child::node()[4] /course/plan/chapter[1]/following-sibling::node()[2] XPath Axes An axis defines a node-set relative to the current node. following is not following-sibling XPath [ Dr. M’hamed MATAOUI ]

XPath XPath Node Set Functions number last() The last function returns a number equal to the context size from the expression evaluation context. number position() The position function returns a number equal to the context position from the expression evaluation context. number count(node-set) The count function returns the number of nodes in the argument node-set. …. XPath [ Dr. M’hamed MATAOUI ]

XPath with JAVA XPath Steps for using XPath in JAVA Following are the steps used while parsing a document using XPath Parser. Import XML-related packages. Create a DocumentBuilder Create a Document from a file or stream Create an Xpath object and an XPath path expression Compile the XPath expression using XPath.compile() and get a list of nodes by evaluating the compiled expression via XPath.evaluate() Iterate over the list of nodes. Examine attributes Examine sub-elements XPath [ Dr. M’hamed MATAOUI ]

XPath with JAVA XPath Example from : See also : https://www.tutorialspoint.com/java_xml/java_xpath_parse_document.htm See also : http://viralpatel.net/blogs/java-xml-xpath-tutorial-parse-xml/ Import XML-related packages import org.w3c.dom.*; import org.xml.sax.*; import javax.xml.parsers.*; import javax.xml.xpath.*; import java.io.*; Create a DocumentBuilder DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document document = builder.parse(new File("xml_filename.xml")); XPath [ Dr. M’hamed MATAOUI ]

XPath with JAVA XPath Build XPath XPath xPath = XPathFactory.newInstance().newXPath(); // ------ Prepare Path expression and evaluate it String expression = "/course/plan/chapter"; NodeList nodeList = (NodeList) xPath.compile(expression).evaluate(document, XPathConstants.NODESET); // ------ Iterate over NodeList for (int i = 0; i < nodeList.getLength(); i++) { Node nNode = nodeList.item(i); // ... // } XPath [ Dr. M’hamed MATAOUI ]

XPath with JAVA XPath Examine attributes //returns specific attribute getAttribute("attributeName"); //returns a Map (table) of names/values getAttributes(); Examine sub-elements //returns a list of subelements of specified name getElementsByTagName("subelementName"); //returns a list of all child nodes getChildNodes(); XPath [ Dr. M’hamed MATAOUI ]

Xpath versions The main new features in XPath 3.1 are: 1. Maps XPath 3 is the latest version of the XML Path Language, a query language for selecting nodes in XML documents. It supersedes XPath 1.0 and XPath 2.0. XPath 3.0 became a W3C Recommendation on 8 April 2014, while XPath 3.1 became a W3C Candidate Recommendation on 17 December 2015. The main new features in XPath 3.1 are: 1. Maps 2. Arrays From : Wikipedia XPath [ Dr. M’hamed MATAOUI ]

XQuery XQuery FLWOR Expressions FLWOR (pronounced "flower") is an acronym for "For, Let, Where, Order by, Return". For - selects a sequence of nodes Let - binds a sequence to a variable Where - filters the nodes Order by - sorts the nodes Return - what to return (gets evaluated once for every node) From : http://www.w3schools.com/ XQuery [ Dr. M’hamed MATAOUI ]

XQuery XQuery FLWOR Expressions (Example) XQuery In plain English, this could be read as "Get all departments that have more than ten employees, order these departments by decreasing average salary, and return a report of department numbers, head counts and average salary in each department" From : Wikipedia XQuery [ Dr. M’hamed MATAOUI ]

XQuery XQuery FLWOR Expressions (Demo example) XQuery [ Dr. M’hamed MATAOUI ]

Adressing and querying XML documents End of this Chapter For more details please visit: https://www.w3.org/TR/xquery-30/ XPath and XQuery [ Dr. M’hamed MATAOUI ]