How to Get all xpaths from XML Content using Java: This tutorial will help you in getting xpath of all the values of your XML content using Java.

Create a project using maven or Gradle or ant or general java project in this tutorial creating a project in maven

Step -1:

  • Right-click on Package explorer New –> Other like below


  • Search for maven in the search box & select maven Project


  • Select Maven Project


  • Check the Create a simple project


  • Add your gorupid, Artifact And click Finish
  • Add below class into your package

import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;

public class XPathMain {

    public static void main(String[] args) throws Exception {
        SAXParserFactory spf = SAXParserFactory.newInstance();
        SAXParser sp = spf.newSAXParser();
        XMLReader xr = sp.getXMLReader();

        xr.setContentHandler(new FragmentContentHandler(xr));
        xr.parse(new InputSource(new FileInputStream("path to your XML file")));

Run the above file to get all xpaths of XML.


Also Read: How to Get all jsonpaths from JSON

How to Get all xpaths from XML Content using Java

Leave a Reply

Your email address will not be published. Required fields are marked *