Home » XPath Tutorials

XPath Tutorials

XPath Tutorials

In this detailed Resource page, we feature an abundance of XPath Tutorials!

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).

The XPath language is based on a tree representation of the XML document, and provides the ability to navigate around the tree, selecting nodes by a variety of criteria. In popular use (though not in the official specification), an XPath expression is often referred to simply as “an XPath”.

Originally motivated by a desire to provide a common syntax and behavior model between XPointer and XSLT, subsets of the XPath query language are used in other W3C specifications such as XML Schema, XForms and the Internationalization Tag Set (ITS).

XPath has been adopted by a number of XML processing libraries and tools, many of which also offer CSS Selectors, another W3C standard, as a simpler alternative to XPath.

Note
If you wish to build up your XPath knowledge first, check out XPath Best Practices Tutorial.

XPath Tutorials – Getting Started

Simple examples on XPath

  • Java XPath Examples
    This article dives into how to construct XPath expressions. Starting with the syntax used to build XPath expressions, and ending with some examples sum up the concepts explored.
  • A Java XPath Best Practices Tutorial
    This example shows how to set up a Java application to create a DOM (Document Object Model) document using a DOM parser to read an XML file; and an XPath object to evaluate XPath expressions as applied to the DOM.
  • Java XPath Performance Tips
    This article focuses attention on tips for improving XPath performance. The code used in this article uses Java SE 8u111. There are no other frameworks nor tools are referenced in this article.
  • Java XPathConstants Example
    In this example, we will be discussing about Java class XPathConstants with an example. Before we start with this article, it is expected that we have a basic understanding of XML. In brief, XML stands for eXtensible Markup Language, which is designed to store and transport data. It is both human and machine readable.
  • Java XPathFactory Example
    In this example, we will see what is java XPathFactory and its usage with example. Before we start with this article, it is expected that we have a basic understanding of XML. XML stands for eXtensible Markup Language, which is designed to store and transport data. It is both human and machine readable.
  • Xpath Unique/Distinct Value Example
    In this article we will learn how to select a distinct value from an XML using XPath. We will use IntelliJ ans an IDE and will use Saxon API for XPATH evaluation.
  • XPath Like Operator Example
    In this example we will learn about XPath like operator. We will see how we can perform a ‘like’ operation using XPath. We will make use of IDEA IntelliJ to show some examples.
  • XPath Union Operator Example
    In this article we will learn about XPath Union operator. The |, or union, operator returns the union of its two operands, which must be node-sets.
  • Get Xpath From Html Example
    In this example we will learn how to find the XPath of a given element in HTML. We will try to use different tools to achieve this.
  • Java XPath Performance DOM vs SAX Example
    This article compares the performance of the Java DOM parser distributed with Java and a SAX parser distributed with the Home Edition of Saxon for evaluating various XPath expressions.
  • Xpath Find by Attribute Value Example
    In this article we will learn how to find an xml element using attribute value. In XPath, there are seven kinds of nodes: element, attribute, text, namespace, processing-instruction, comment, and document nodes. XML documents are treated as trees of nodes.
  • Xpath Search by id Example
    In this article we will learn how to search for an element (by id) in an XML using XPath. We will make use of IDEA IntelliJ to work on this. In this section we will see how to search an xml element using id. First we will discuss how to create a project using IntelliJ. Then we will write the code for it.
  • XPath parent node example
    In this example, we shall talk about the ancestor axis in XPath Expression. The ancestor tag is used to select the ancestor of the current node and the ancestor of the ancestor and so on in context of the current node.
  • XPath ancestor example
    In this example we will learn how to get the ancestor details of a given node using XPath. We will start with the introduction of XPath – what it is and how to use it, then we will see the working model of the desired functionality.
  • XPath descendant example
    In this example we shall talk about the Descendant axis specifier in XPath. An axis specifier indicates the direction of navigation in DOM tree of that XML document. This helps in effectively querying the XML document.
  • XPath innertext selection example
    In this example we will learn how to select a node with a given inner text using XPath. We will start with the introduction of XPath – what it is and how to use it, then we will see the working model of inner-text selection. Tools and technologies used in this example are Java 1.6, Intellij.
  • XPath count example
    In the previous example, we studied how to use the XPath Concat method. In this example, we will see how to use the count method in XPath. The XPath count() method is used to count the number of nodes matching a given XpathExpression.
  • XPath ends-with example
    In this example we will learn how to use the ends-with function of XPath. We will start with the introduction of XPath – what it is and how to use it, then we will see the working model of ends-with function.

XPath Tutorials – Functions

Learn the basic functionalities of XPath

  • XPath concat Example
    The XPath-concat method works similar to the String#concat method. It joins two or more strings into a single string. The argument strings maybe two or more static strings and/or they may be two or more XPathExpression to evaluate. The output from the XPathExpressionis then concatenated and the resulting string is returned.
  • XPath normalize-space example
    In this example, we will talk about the normalize-space method in XPath. The normalize-space(String s) method is used to normalize a string i.e. to remove any leading or trailing spaces from the string s passed as parameter to the XPath function.
  • XPath substring example
    In this example, we will try to see how we can use the sub-string method in the XPath for our use-cases. The sub-string method is used to search for the sub-string in the beginning or the end or anywhere in the XPath node.
  • XPath preceding-sibling example
    In this example we will learn how to use the preceding-sibling function of XPath. We will start with the introduction of XPath – what it is and how to use it, then we will see the working model of ‘preceding-sibling’ function.
  • XPath local-name example
    Continuing on the series of examples about XPath, we will see how we can use the local-name function in Java. We use this XPath function we need to work with namespaces.
  • XPath following-sibling example
    In this example we will learn how to use the following-sibling function of XPath. We will start with the introduction of XPath – what it is and how to use it, then we will see the working model of ‘following-sibling’ function.
  • XPath String functions example
    In this example, we shall see what other String operations on XPath are supported by the Java programming language. The String operations are a range of functions that may be used to search/query. These functions operate on string variables or return a string in specific format.
  • XPath starts-with example
    In this example we will learn how to use starts-with function of XPath. We will start with the introduction of XPath – what it is and how to use it, then we will see the working model of ‘starts-with’ function.
  • XPath get attribute value example
    In the example, the name of the cricketer is known. We have to determine the handedness of the cricketer, which is mentioned in the type attribute of the XPath.
  • XPath contains text example
    In this example, we shall study how to search for a particular text using XPath in Java.

XPath Tutorials – Integrations

Learn how to use XPath in various platforms and frameworks

  • Eclipse XPath Evaluation Plugin Example
    In this tutorial, we will learn to use the XML and XPath Editor available through the Web Tools Platform (WTP) within Eclipse.
  • Apache Camel XPath Example
    In this article, we will look into examples of XPath. We will use XPath to create a Predicate in a Message Filter.
  • XPath XSLT Tutorial
    In this article we will learn how to use XPath in XSLT. In this section we will learn about the various terminologies used in XPath.
  • Java XPath Using SAX Example
    This is a Java XPath Using SAX Example. SAX parsers are most commonly used by subclassing the DefaultHandler() method to suit your needs. Some SAX parsers do have a JAXP API interface that allows for the evaluation of XPath expressions.
  •  Using XPath in Selenium Example
    In this example we will learn how to use XPath in Selenium. We will start with the introduction of Selenium and XPath – what it is and how to use it, then we will see the working model of how to use XPath in Selenium tests.
  • XPath Jmeter Example
    In this article we will learn how to use XPath in JMeter. For this example we will use JMeter 3.2 and Java 8. The Apache JMeter application is open source software, a 100% pure Java application designed to load test functional behavior and measure performance.
Do you want to know how to develop your skillset to become a Java Rockstar?
Subscribe to our newsletter to start Rocking right now!
To get you started we give you our best selling eBooks for FREE!
1. JPA Mini Book
2. JVM Troubleshooting Guide
3. JUnit Tutorial for Unit Testing
4. Java Annotations Tutorial
5. Java Interview Questions
6. Spring Interview Questions
7. Android UI Design
and many more ....
I agree to the Terms and Privacy Policy