1 JAXP & XPATH. Objectives 2  XPath  JAXP Processing of XPath  Workshops.

Slides:



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

Dr. Alexandra I. Cristea XPath and Namespaces.
Bottom-up Evaluation of XPath Queries Stephanie H. Li Zhiping Zou.
UFCEKG-20-2 Data, Schemas & Applications Lecture 5 XML & PHP.
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.
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.
Xerces The Apache XML Project Yvonne Yao. Introduction Set of libraries that provides functionalities to parse XML documents Set of libraries that provides.
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.
Cornell CS 502 More XML XML schema, XPATH, XSLT CS 502 – Carl Lagoze – Cornell University.
September 15, 2003Houssam Haitof1 XSL Transformation Houssam Haitof.
Introduction to XPath Bun Yue Professor, CS/CIS UHCL.
SD2520 Databases using XML and JQuery
Xpath Sources:
CSE 6331 © Leonidas Fegaras XML Tools1 XML Tools Leonidas Fegaras.
10/06/041 XSLT: crash course or Programming Language Design Principle XSLT-intro.ppt 10, Jun, 2004.
1 XML Data Management 4. Domain Object Model Werner Nutt.
XML Anisha K J Jerrin Thomas. Outline  Introduction  Structure of an XML Page  Well-formed & Valid XML Documents  DTD – Elements, Attributes, Entities.
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 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.
Introduction to XPath Transparency No. 1 Introduction to XPath API Cheng-Chia Chen.
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,
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.
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.
17 Apr 2002 XML Programming - DOM Andy Clark. DOM Design Premise Derived from browser document model Defined in IDL – Lowest common denominator programming.
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.
CSE 6331 © Leonidas Fegaras XML Tools1 XML Tools.
1 JAXP & XSLT. Objectives 2  TrAX API  Transforming XML Documents  Workshops.
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.
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.
1 XSLT An Introduction. 2 XSLT XSLT (extensible Stylesheet Language:Transformations) is a language primarily designed for transforming the structure of.
XSLT Kanda Runapongsa Dept. of Computer Engineering Khon Kaen University.
Sheet 1XML Technology in E-Commerce 2001Lecture 3 XML Technology in E-Commerce Lecture 3 DOM and SAX.
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.
[ Part III of The XML seminar ] Presenter: Xiaogeng Zhao A Introduction of XQL.
XML Refresher Course Bálint Joó School of Physics University of Edinburgh May 02, 2003.
CSE 6331 © Leonidas Fegaras XML Tools1 XML Tools.
XML and Database.
Document Object Model DOM. Agenda l Introduction to DOM l Java API for XML Parsing (JAXP) l Installation and setup l Steps for DOM parsing l Example –Representing.
CS 157B: Database Management Systems II February 13 Class Meeting Department of Computer Science San Jose State University Spring 2013 Instructor: Ron.
XML and Object Serialization. Structure of an XML Document Header Root Element Start Tags / End Tags Element Contents – Child Elements – Text – Both (mixed.
XPath. XPath, the XML Path Language, is a query language for selecting nodes from an XML document. The XPath language is based on a tree representation.
More XML XPATH, XSLT CS 431 – February 23, 2005 Carl Lagoze – Cornell University.
1 Introduction JAXP. Objectives  XML Parser  Parsing and Parsers  JAXP interfaces  Workshops 2.
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.
Web services. DOM parsing and SOAP.. Summary. ● Exercise: SAX-Based checkInvoice(), ● push parsing, ● event-based parsing, ● traversal order is depth-first.
Friday, September 4 th, 2009 The Systems Group at ETH Zurich XML and Databases Exercise Session 5 courtesy of Ghislain Fourny/ETH © Department of Computer.
XPath --XML Path Language Motivation of XPath Data Model and Data Types Node Types Location Steps Functions XPath 2.0 Additional Functionality and its.
Lecture 23 XQuery 1.0 and XPath 2.0 Data Model. 2 Example 31.7 – User-Defined Function Function to return staff at a given branch. DEFINE FUNCTION staffAtBranch($bNo)
1 XPath. 2 Agenda XPath Introduction XPath Nodes XPath Syntax XPath Operators XPath Q&A.
Jackson, Web Technologies: A Computer Science Perspective, © 2007 Prentice-Hall, Inc. All rights reserved Chapter 7 Representing Web Data:
1 Validation SAX-DOM. Objectives 2  Schema Validation Framework  XML Validation After Transformation  Workshops.
XML. Contents  Parsing an XML Document  Validating XML Documents.
Unit 4 Representing Web Data: XML
Querying and Transforming XML Data
{ XML Technologies } BY: DR. M’HAMED MATAOUI
Chapter 7 Representing Web Data: XML
WaysInJavaToParseXML
XML document processing in Java using XPath and XSLT
More XML XML schema, XPATH, XSLT
WaysInJavaToParseXML
Presentation transcript:

1 JAXP & XPATH

Objectives 2  XPath  JAXP Processing of XPath  Workshops

XPath  Is needed to efficiently access the XML data located in different nodes in a database.  Is a query language, which uses path expressions to traverse through XML documents.  Features  It is a strongly typed language.  It uses sequences, comparisons, quantified expressions, and ranges

XPath Data Model  Is a concept, which traverses the tree model and divides each XML document into seven types of nodes.  The XPath query works on an XML document as a tree.  In the XPath data model, each node has a string value. Also, the names used for attributes, elements, and namespace nodes are divided into two types, local names and namespace names.  XPath data model has no contiguous text node.

XPath Data Model (cont)  Root Node  Is the root of the tree.  Does not occur anywhere except as the root of the tree.  The purpose of root node is it binds all other nodes in the XML document.  Element Node  An element node associated with each element.  The text nodes and subordinate al nodes are the child nodes of an element in a single place in XML document.  Attribute Node  Each element has a connected set of attribute nodes.  Can never be child of its parent element. This is because it does not consider the element bearing an attribute as the parent of the attribute.  The purpose of attribute node is to keep the attributes in a single place in XML document.  Text Node  In a text node, the character data is arranged in a group.  Keeps the characters in XML document.

XPath Data Model (cont)  Comment Node  Every comment has a comment node in the XML document. But this rule is not applicable if the comment takes place within the document type declaration.  The purpose of comment node is to keep the comment in a single place in XML document.  Processing Instruction Node  Are included in the XML document prolog, normally considered as a header. The prolog is a component of XML document, which consists of DTD and declaration.  Every processing instruction has a processing instruction node in the XML document. But this rule is not applicable if the Processing Instruction takes place within the document type declaration.  Namespace Node  Each element has a connected set of namespace nodes.  An element have a namespace node for every attribute on that element whose name starts with xmlns:.  The purpose of namespace node is to keep the elements with the namespace node.

Naming & Binding Naming Context  Namespace Context  To use a namespace context in a query, you must declare the namespace in the XML  More than one namespace context can be declared, if needed, in a query.  The NamespaceContext interface is used for reading the XML namespace context processing.  Some properties  Namespace URI, where the prefix is bound.  Prefix, which is a part of the attribute name.  Binding Namespace Context  The namespace URI can be bound to more than one prefixes in the current scope. But a prefix can bound to a single namespace URI in the current scope MethodsDescriptions getNamespaceURI - public String getNamespaceURI(String prefix) - Is used in the current scope to get namespace URI bound to a prefix getPrefix - public String getPrefix(String namespaceURI) - Is used in the current scope to get prefix bound to namespace URI getPrefixes - public Iterator getPrefixes(String namespaceURI) - Is used in the current scope to get all prefixes bound to a namespace URI

JAXP API for XPath  Is defined in the javax.xml.xpath package  The interfaces of JAXP APIs that are used for XPath processing are  XPath  The XPath interface gives an easy and robust syntax for traversing through the nodes in an XML document.  Using XPath, you can change a node in a DOM tree to string or Boolean.  XPathExpression  The XPathExpression interface deals with location path and predicates. Predicates are symbols like // or /, which allows you to elaborate the nodes selected by XPath.  In an XPath expression, you can include XPath variables. The variables used in XPath are called as XPath variables. A reference to an XPath variable starts with “$” and can only occur in match, test, get, and set  The classes of JAXP APIs used for XPath processing are:  XPathFactory: the XPathFactory class is used for creating XPath objects.  XPathConstants: the XPathConstants class defines the data types such as Boolean, NodeSet, number, and string for working with nodes in and XML document

Example public class XPathEx { public static void main (String[] args) { int count = 0; try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance (); DocumentBuilder builder = dbf.newDocumentBuilder (); Document doc = builder.parse (new File(args[0])); XPathFactory xpf = XPathFactory.newInstance (); XPath xpath = xpf.newXPath (); NodeList list = (NodeList)xpath.evaluate ("//customers/customer/item", doc, XPathConstants.NODESET); for(int i=0; i<list.getLength (); i++){ if(list.item (i).getTextContent ().equalsIgnoreCase (args[1])) count++; } System.out.println("Out of " + list.getLength () + " customers " + count + " customers have place an order for " + args[1]); }catch(Exception e){ e.printStackTrace ();} }

Example (cont) Chris Color TV David DVDPlayer Mitchell Washing Machine

Processing Namespace Context  JAXP API provides the NamespaceContext interface to establish the namespace relationship when an XPath expression is evaluated.  In a context document, the XPath expression selects all the elements from attributes and namespaces MethodsDescriptions setNamespaceContext - public void setNamespaceContext(NamespaceContext ns) - Is used to set up a namespace context setXPathFunctionResolver - public void setXPathFunctionResolver(XPathFunctionResolver resol) - Is used to set up a function resolver

Example public class NamespaceContextEx { public static void main (String[] args) { try{ XPath xpath = XPathFactory.newInstance ().newXPath (); xpath.setNamespaceContext (new PersonalNamespaceContext()); String expression = "//Aptech/student/grad:name/text()"; InputSource input = new InputSource(args[0]); NodeList list = (NodeList)xpath.evaluate (expression, input, XPathConstants.NODESET); System.out.println("List of grad students: total - " + list.getLength ()); for(int i=0; i<list.getLength (); i++){ System.out.println("\t" + list.item (i).getNodeValue ()); } }catch(Exception e){} }

Example (cont) Christine Illinois Burton Colorado Peterson New Mexico Corrine

WORKSHOP ACTIVITIES Building the console Java application using XPath to Find and count the item element in XML document Parsing naming context to find, count and print the filtered content in XML file