• 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

xpath and java (SDK 5)

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

I have a problem using xpath from within java. I have an example XML file that looks somethink like this:



And some very simple java code to parse it (I've removed all te try/catch blocks and function calls to just show the relevant parts):



where dbFile is the path to the XML file iven earlier.

When searchTerm= "/catalog", a get a string representation of all the nodes in the xml document as expected.

If search term is either:
/catalog//cd
or
//cd

I only get the first cd node returned. I would have expected to have all cd nodes returned. What am I doning wrong here ??

Note: /catalog/cd[1] and /catalog/cd[2] work as expected.

Any ideas ?

Clive
 
Marshal
Posts: 28174
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
I think maybe you're expecting incorrectly? I can't tell from the documentation, but I think it's possible that converting a node-set to a string just picks the first node from the set and returns its string value. This is how <xsl:value-of> in XSLT handles a node-set, for example. Try returning a node-set instead, something like:
 
clive jordan
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Paul,

I appreciate your reply. This makes sense, at least I can see what is going on now. Thanks again !

Clive
 
reply
    Bookmark Topic Watch Topic
  • New Topic