Meaningless Drivel is fun!*
The moose likes XML and Related Technologies and the fly likes What's wrong with my xpath logic here? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "What Watch "What New topic
Author

What's wrong with my xpath logic here?

Chris Corbyn
Ranch Hand

Joined: Jan 14, 2007
Posts: 114
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

Joined: Jan 14, 2007
Posts: 114
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

Joined: Jan 14, 2007
Posts: 114
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
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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

Joined: Jan 14, 2007
Posts: 114
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: What's wrong with my xpath logic here?
 
Similar Threads
Tomcat servlet-mapping bypass if real file requested
Can't pin down this NullPointerException :(
Using Directory Path as Parameters?
Servlet Map vs Static Resource
Why does getParameterMap() return an *immutable* Map?