Web Data Management
Prof. C Sheeja Justin, Assistant Professor
IT & Computer Science
Unit 2-Xpaths
XPath Basics
Types of Xpaths
XPath steps and expressions
<bookstore> //open xpath online realtime tester
<book category="cooking">
<title lang="eng">Everyday routine </title>
<author>smith </author>
<year>2022</year>
<price>30.00</price>
</book>
<book category="children">
<title lang="eng">Harry Potter</title>
<author>jk.Rowling</author>
<year>2024</year>
<price>30.00</price>
XPath (XML Path Language)
XPath is a query language for selecting nodes in an XML
document.
It provides a way to navigate and extract information from XML
documents.
XPath Types
1.Absolute Xpath
2.Relative Xpath
Absolute Xpath:traversing or navigating from root element of the
document to child element of the document with the help of single
forward slash
Means coming down Step by step or one by one
This makes your Xpath performance is very slow
Syntax:/tagname
Eg)/bookstore/book[2]/author
2.Relative Xpath
Starts from any point in the document based on the search criteria with the
help of double forward slashes
Means directly come to the particular node or element.
Ex)//tagname[@attribute name=‘attribute value’]
//*/article/keywords
Key Components
1.Nodes in XML:
Root Node: The topmost element.
Element Node: Tags in the XML.
Attribute Node: Attributes of elements.
Text Node: Text within an element.
2.XPath types Syntax:
Absolute Path: Starts from the root (e.g., /root/child).
Relative Path: Starts from the current node (e.g., .//*/child).