Exception in eval of XPATH API Try other way A location step was expected following the '/' or '//' token.

I am getting this error while calling the following code:
import java.io.File;

import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;
public static void main(String[] args) {
            String omxml =
                  "C:\\TestDir\testObj\TestFile.xml";      
            File tfile = new File(omxml);
            
            try {
                   doc  = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(tfile);
                  }catch(Exception eee){
                    eee.printStackTrace();
                  }
newone2011Asked:
Who is Participating?
 
for_yanConnect With a Mentor Commented:

look for some xPath.evaluate comand in the code - something looking like this one:

list = (NodeList) xPath.evaluate("(//ns:sessionUID)|(//ns:eNewSTok)",  source, XPathConstants.NODESET);

Open in new window

0
 
CEHJCommented:
Just from that code!? Can you possibly attach TestFile.xml to this q?
0
 
for_yanCommented:

You should use \\ instead of one \
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
for_yanCommented:
  "C:\\TestDir\\testObj\\TestFile.xml";      
0
 
for_yanCommented:
You cannot use one backslash in the filepath in Java code as backshlash has a special meaning - in all cases you should use two backslashes
not only in the beginning
0
 
CEHJCommented:
Missed that ;)

Much easier to do

 "C:/TestDir/testObj/TestFile.xml";      
0
 
for_yanCommented:
No difference -  "C:/TestDir/testObj/TestFile.xml";       or this  "C:\\TestDir\\testObj\\TestFile.xml";      
With a single backslsh - this is a problem
0
 
newone2011Author Commented:
I am sorry, made a mistake while typing. It does have 2 backslashes, see below.
mport javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;
public static void main(String[] args) {
            String omxml =
                 "C:\\TestDir\\testObj\\TestFile.xml";                  File tfile = new File(omxml);
           
            try {
                   doc  = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(tfile);
                  }catch(Exception eee){
                    eee.printStackTrace();
                  }

The test file has following contents:
<?xml version="1.0" encoding="UTF-8"?>
<TestVOM>
        
      <ApplicationConfig>

      <TestWebServiceURL>http://www.test.com/Test.asmx</TestWebServiceURL>
</ApplicationConfig>
</TestVOM>
0
 
for_yanCommented:
So which line is throwing this execption - and can you post the stacktrace ?
and corresponding lines which are referreed in the stacktrace ?
0
 
newone2011Author Commented:
Its showing this in Tomcat logs:
Exception in eval of XPATH API Try other way A location step was expected following the '/' or '//' token
without any line no.

Just trying to make sure if it is being thrown elsewhere in a jar file code. Will update you. Thx
0
 
newone2011Author Commented:
Ok, will do thx. Will let you know.
0
 
newone2011Author Commented:
Added points for effort
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.