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();
                  }
Java

Avatar of undefined
Last Comment
newone2011
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?
Avatar of for_yan
for_yan
Flag of United States of America image


You should use \\ instead of one \
Avatar of for_yan
for_yan
Flag of United States of America image

  "C:\\TestDir\\testObj\\TestFile.xml";      
Avatar of for_yan
for_yan
Flag of United States of America image

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

Missed that ;)

Much easier to do

 "C:/TestDir/testObj/TestFile.xml";      
Avatar of for_yan
for_yan
Flag of United States of America image

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>
Avatar of for_yan
for_yan
Flag of United States of America image

So which line is throwing this execption - and can you post the stacktrace ?
and corresponding lines which are referreed in the stacktrace ?
Avatar of newone2011
newone2011

ASKER

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

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of newone2011
newone2011

ASKER

Ok, will do thx. Will let you know.
Avatar of newone2011
newone2011

ASKER

Added points for effort
Java
Java

Java is a platform-independent, object-oriented programming language and run-time environment, designed to have as few implementation dependencies as possible such that developers can write one set of code across all platforms using libraries. Most devices will not run Java natively, and require a run-time component to be installed in order to execute a Java program.

102K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo