Link to home
Start Free TrialLog in
Avatar of newone2011
newone2011

asked on

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();
                  }
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

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

You should use \\ instead of one \
  "C:\\TestDir\\testObj\\TestFile.xml";      
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
Missed that ;)

Much easier to do

 "C:/TestDir/testObj/TestFile.xml";      
No difference -  "C:/TestDir/testObj/TestFile.xml";       or this  "C:\\TestDir\\testObj\\TestFile.xml";      
With a single backslsh - this is a problem
Avatar of newone2011
newone2011

ASKER

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>
So which line is throwing this execption - and can you post the stacktrace ?
and corresponding lines which are referreed in the stacktrace ?
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
ASKER CERTIFIED SOLUTION
Avatar of for_yan
for_yan
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Ok, will do thx. Will let you know.
Added points for effort