• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What's wrong with my xpath logic here?

 
Chris Corbyn
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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)



 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic