• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Search using XPath

 
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello

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:
HannaH
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:

word[contains(*,'happy')]

 
H Melua
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Evaluating XPath:

gives 'i'm feeling happy'
 
H Melua
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks very much guys

I guess the problem is somewhere else

-----------------------------------

EDITED!!!

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 ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic