wood burning stoves 2.0
The moose likes XML and Related Technologies and the fly likes Search using XPath Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Search using XPath" Watch "Search using XPath" New topic

Search using XPath

H Melua
Ranch Hand

Joined: Jan 04, 2005
Posts: 172

I'd like to know how to search for a particular word in a child element.. like searching for the word "happy" in

<word>i'm feeling happy<word>

I can search for the whole sentence, and i can check using "contains" function that the word actually exists there, but i want it to return the element not just returns true!

any ideas?

thanks :thumb:
Paul Clapham

Joined: Oct 14, 2005
Posts: 19742

You want elements where the text contains "happy"? When your requirements contain that word "where", that means you should use a predicate. So your XPath would look like this:
H Melua
Ranch Hand

Joined: Jan 04, 2005
Posts: 172
Thanks, but that doesnt seem to return anything at all

i've tried doing this..

but that didnt work either , when i check the list returned from this query, it tell me that the size of the list is 3 (which is right) but when i try to extract the word element using

it returns null
Craig Bayley
Ranch Hand

Joined: Sep 27, 2007
Posts: 46

Evaluating XPath:

gives 'i'm feeling happy'
H Melua
Ranch Hand

Joined: Jan 04, 2005
Posts: 172
Thanks very much guys

I guess the problem is somewhere else



now it works!!! bloody hell, it took me weeks to figure out why it wasnt doing it!! i had to demonstrate 2 of my assignments without making my lecturer realise that the search wasnt working correctly!

oh well, now it does

Thanks very much again :thumb:
[ November 27, 2007: Message edited by: H Melua ]
I agree. Here's the link: http://aspose.com/file-tools
subject: Search using XPath
It's not a secret anymore!