This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes XML and Related Technologies and the fly likes Using conditions in compiling xpath Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Using conditions in compiling xpath" Watch "Using conditions in compiling xpath" New topic
Author

Using conditions in compiling xpath

sony vijay
Ranch Hand

Joined: Jun 27, 2010
Posts: 32
Hi,

Is there a way to compile an xpath expression and return a "String" based on the result ? Meaning, say I compile the following xpath expressions:

./libx:package
./libx:libapp
./libx:module

I want to compile each of the above strings in a condition and return "Package", "Libapp", "Module" respectively if the xpath expression is found in the given XML.

I used the following code to achieve this: (target is the XML passed when the getEntryType method is called)



This code works. But, I am wondering if there is a simpler way to do it? Something like if "expression" compiled true return "String". I remember seeing something like this ( "[./libx:package]\"Package\" )somewhere but not sure of it is right.

Thanks,
Sony

 
 
subject: Using conditions in compiling xpath
 
Similar Threads
XPath expression constrained by a predicate doesn't work (//element[@attribute="value"])
Can't pin down this NullPointerException :(
How to perform an XPath Query with namespaces.
Please help in XPath to parse XML with namespace
XPath and Modified DOM document object...