Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Invalid xpath expression

 
Dennis Zandvliet
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm using Xalan extension function to call a java function like this:




But i keep getting this error, regardless of what xpath expression i use.




Any clues?




 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Weird. That is valid XPath syntax. What happens if you try a differernt selector, //* for example?
 
Dennis Zandvliet
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm sorry the errormessage is a bit misleading, it was thrown by wrapper method of



This is the original error:



This selector //* also give the same error.


formnode.getNodeType() gives type ELEMENT;


I've also tried this:





Also give the same error:

 
Paul Clapham
Sheriff
Posts: 21298
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can we clarify your throwaway remark about "Xalan extension function"?

If I understand this right, you have an XSL transformation. And from that you're calling Java methods. And from those Java methods you're calling this code that you have shown us. And the intent of the XPath is that it should be operating on the nodes of the XML document that is being transformed? Is that correct?

I can certainly see how that would be a stretch to make that scheme work, if that's actually what you are trying to do, but I don't have anything helpful to say about it at the moment. Except that you might have a look at just what it is you're trying to apply the XPath expression to. A little debugging, that is. Do you actually have a Node object? Things like that.
 
Dennis Zandvliet
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:Can we clarify your throwaway remark about "Xalan extension function"?

If I understand this right, you have an XSL transformation. And from that you're calling Java methods. And from those Java methods you're calling this code that you have shown us. And the intent of the XPath is that it should be operating on the nodes of the XML document that is being transformed? Is that correct?



Yes, almost correct, the nodes are not from XML document itself but generated in the xslt and bind to a variable which is than passed to the java method.

Something like this:
When, in the Java method, I convert the node-tree to a string I get a xml document, with all the expected elements. So I'm sure the node is not empty.



Paul Clapham wrote:Can we clarify your throwaway remark about "Xalan extension function"?
Do you actually have a Node object? Things like that.


Yes, because when i do formnode.getNodeType() it gives type ELEMENT;
Also all the other methods work, like getChildNodes() etc.
 
Paul Clapham
Sheriff
Posts: 21298
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah... you're generating the nodes in the XSLT. So perhaps they don't belong to any document, and calling getOwnerDocument returns something peculiar?
 
Dennis Zandvliet
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:Ah... you're generating the nodes in the XSLT. So perhaps they don't belong to any document, and calling getOwnerDocument returns something peculiar?


Yes i was also thinking in this direction. But it this the case
1) How can i make them part of a proper created en initialised DOM document?
2) How is it possible that the nodes are not part of a document, because according to Sun's documentation nodes are always part of an document?
3) How come that after this call

Document doc = formnode.getOwnerDocument();

I can call al the other regular methods like getElementsByTagName() on this class?

I'ts very late here, i'm gonna try it tomorrow

Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic