Search code examples
javamavenxpathruntimeexception

How to solve error java.lang.RuntimeException for XPATH ? MAVEN dependencies added


I am getting following error

 java.lang.RuntimeException:  Trying XBeans path engine... Trying XQRL... Trying XDK... Trying delegated path engine... FAILED on data(//v:shape[contains(@id,'PowerPlusWaterMarkObject')]/v:textpath/@string)

while executing following code

private String getWaterMark(XWPFDocument document) {
   try {
        XWPFHeader defaultHeader = document.getHeaderFooterPolicy().getDefaultHeader();
        final String xpathFilter = "data(//v:shape[contains(@id,'PowerPlusWaterMarkObject')]/v:textpath/@string)";
        XmlObject[] xmlobjects = defaultHeader._getHdrFtr().selectPath(xpathFilter);
        return xmlobjects[0].toString();
   } catch (Exception ex) {
       logger.error("Error while getting Watermark content from document: ", ex);
   }
}

I have added following dependencies in pom.xml file.

        <!-- https://mvnrepository.com/artifact/org.apache.xmlbeans/xmlbeans-xpath -->
        <dependency>
            <groupId>org.apache.xmlbeans</groupId>
            <artifactId>xmlbeans-xpath</artifactId>
            <version>2.6.0</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/net.sf.saxon/Saxon-HE -->
        <dependency>
            <groupId>net.sf.saxon</groupId>
            <artifactId>Saxon-HE</artifactId>
            <version>10.6</version>
        </dependency>


Solution

  • I just replaced my XPATH and it solved my problem

    *//v:shape/v:textpath/@string