[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Determining if an XPATH is valid

Posted on 2006-05-06
7
Medium Priority
?
209 Views
Last Modified: 2013-11-23
Hello,
I have an XML document which contains various paths (I use xpath to retrieve the values). What I need to be able to do is detect if the path I am looking for is valid. Can someone please tell me how to do this?

Worth 500 points.

Thanks,
Rick
0
Comment
Question by:richardsimnett
  • 4
  • 2
7 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 16621570
May one ask why?
0
 

Author Comment

by:richardsimnett
ID: 16621723
I have a function which needs to determine if a configuration option is set or not prior to retrieving the value for the XPATH. If the option is not in the XPATH, I want to return a default value, if it is then just retrieve the value as normal. So I was thinking about adding a function called CheckXPATH(String path) which returns a boolean for whether it exists or not. I just cant seem to figure out how to determine if it exists.

Thanks,
Rick
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16621797
I don't understand that really. Perhaps you can explain in different words? In the meantime, i'll take a guess: all you can do is to search the DOM with the XPath and then return the default value if it doesn't match
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 30

Accepted Solution

by:
Mayank S earned 2000 total points
ID: 16622083
Depending on the API you are using, either the Xpath should return null or throw an exception - in which case you will know that it is not valid.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16628635
>>throw an exception

I think that's unlikely
0
 

Author Comment

by:richardsimnett
ID: 16628675
CEHJ,
Actually in java 1.5.0-b06 it does throw an exception when the path cannot be found. So capturing that and having the function return null, and testing for the null result after the call allows me to return the default value as needed.

Thanks,
Rick
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16628695
>>when the path cannot be found

Really - meaning that the path is valid but couldn't be matched or meaning that the path is invalid?
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses
Course of the Month20 days, 1 hour left to enroll

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question