aspose file tools*
The moose likes XML and Related Technologies and the fly likes Invalid xpath expression Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Invalid xpath expression" Watch "Invalid xpath expression" New topic
Author

Invalid xpath expression

Dennis Zandvliet
Ranch Hand

Joined: Jun 19, 2008
Posts: 60
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

Joined: Apr 14, 2004
Posts: 10336

Weird. That is valid XPath syntax. What happens if you try a differernt selector, //* for example?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Dennis Zandvliet
Ranch Hand

Joined: Jun 19, 2008
Posts: 60
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
Bartender

Joined: Oct 14, 2005
Posts: 18989
    
    8

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

Joined: Jun 19, 2008
Posts: 60
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
Bartender

Joined: Oct 14, 2005
Posts: 18989
    
    8

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

Joined: Jun 19, 2008
Posts: 60
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Invalid xpath expression