• Post Reply Bookmark Topic Watch Topic
  • New Topic

XPath problem  RSS feed

 
Miran Cvenkel
Ranch Hand
Posts: 208
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
XPath:

/Data/Table/Information/Group[@type='nomenclature']/Group[@type='language' and @value='en']/Group[@type='dictionary' and @value='context']/Element[@name='code' and @value='tag00061']/AttList/Att[@name='label']

src:
source xml link

xpath tested here tester and works OK!



But here falls into exception ?
msg: malformed expresion
cause:premature EOF


 
Miran Cvenkel
Ranch Hand
Posts: 208
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so, figured, that the third line added solves the problem. What does that mean, that xpath.evaluate changes xml object inputStream somehow?
Which I doubt as I tested it, inputStream.hashcode is same on second run.

 
Paul Clapham
Sheriff
Posts: 22844
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, if you think about it, evaluating the XPath expression on an InputStream (which must contain XML) requires reading the XML from that InputStream. So after that, there's nothing left to read from the InputStream. Which would explain why you get the message saying that the InputStream is at the end of the file if you try to use it again.

I don't know why you think the hashcode of the InputStream has anything to do with it. That isn't going to change as you read data from the stream.
 
Miran Cvenkel
Ranch Hand
Posts: 208
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, I guess inputStream is there, on the second run as it was at first run , it is just that it is at the end of file.

So, can it be moved to the start of file or something ?
 
Miran Cvenkel
Ranch Hand
Posts: 208
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the solution is there,tested, I can read it as many times as I need to:
reusable input stream





Not certain doh, do I have to close stream manualy then, or the system takes care of it eventualy ?
 
Paul Clapham
Sheriff
Posts: 22844
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're fixing the wrong problem there. Anyway when your "fix" immediately requires another fix, you should suspect you're doing the wrong thing.

Here's why your fix is wrong: every time you apply an XPath expression to an InputStream, the XML read from the stream has to be parsed first. So your idea of reusing the InputStream was not such a good idea. It would be better to parse the InputStream -- once only -- into a DOM structure, and then to apply your XPath expressions to that DOM. That way the parsing only takes place once.
 
Miran Cvenkel
Ranch Hand
Posts: 208
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks.

I was parsing dom structure at first, without xpath, only to find that , I'm not getting anywhere because sunner or later dom document became unusable as I removed elements, and had to load document again for each parsing.

Mybe xpath does not 'corrupt' dom document, wil try that.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!