• 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

What's wrong with my xpath logic here?

 
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm trying to traverse a simple XML document looking like this:



The sequence of expressions I'm running are:



Now basically, it's finding the nodes from the first expression just fine, but when it gets into that loop and starts running expressions against each node it's throwing XPathExpressionException, but getMessage() in the exception just returns "null". I'm confused but I'm not really familiar with XPath so I'm guessing I'm just using it wrongly.
[ August 16, 2007: Message edited by: Chris Corbyn ]
 
Chris Corbyn
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hmm, I've just noticed if I run an expression successfully on the InputSource object, then run that same expression on the same InputSource again it fails the second time. Does XPath somehow move you into the tree everytime you run an expression?

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

Changing from repeatedly using the same InputSource to using DocumentBuilder to create a document first solved the problem. If someone could explain why I'd be very greatful

(I also changed some expressions to use relative paths)



 
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
That's a lot of code there, and I haven't really looked at it. My guess is that by doing an XPath query on an InputSource you are consuming the input from some kind of a stream. Then doing a second query wouldn't work because you couldn't reread the data from the stream.
 
Chris Corbyn
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My thoughts too. I'm guessing InputSource (unlike InputStream) is just read entirely in one go. I should check the API I suppose

Cheers,

Chris
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic