Skip to main content
Announcements
Introducing a new Enhanced File Management feature in Qlik Cloud! GET THE DETAILS!
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

[resolved] XPath with context variables not working

I have defined a context variable that should be used in my xpath.
I have created a route with the following xpath entry for testing purpose.
"concat('XPath ','is ',)"+context.emotion,String.class
where emotion is a context variable with value AWFUL!
This is the error that I get.
org.apache.camel.builder.xml.InvalidXPathExpression: Invalid xpath: concat('XPath ','is ',)AWFUL!. Reason: javax.xml.xpath.XPathExpressionException
Any idea on how to resolve this?

Labels (2)
1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

Hi sijujohn
you need to construct a valid xpath statement. The xpath statement currently being generated is not valid.
concat('XPath ','is ',)AWFUL!
First, AWFUL! needs to be inside the parentheses and it needs to be inside quotes. Don't confused by the context variable. You are just building a string that happens to be an xpath expression. If you construct a string that is not valid, then you are going to get an error. I believe the xpath expression you want is:
concat('XPath ','is ', 'AWFUL!')
So your expression in Studio should read:
"concat('XPath ','is ', '"+context.emotion,String.class + "')"
Note that I have added an additional set of single quotes around the AWFUL that is being retrieved from the context.

View solution in original post

3 Replies
Anonymous
Not applicable
Author

Can you show a little more of your route? It looks like the concat part is used literally in the xpath.
Anonymous
Not applicable
Author

Attached is the image of the route.
The xpath is being applied at the setBody.
Anonymous
Not applicable
Author

Hi sijujohn
you need to construct a valid xpath statement. The xpath statement currently being generated is not valid.
concat('XPath ','is ',)AWFUL!
First, AWFUL! needs to be inside the parentheses and it needs to be inside quotes. Don't confused by the context variable. You are just building a string that happens to be an xpath expression. If you construct a string that is not valid, then you are going to get an error. I believe the xpath expression you want is:
concat('XPath ','is ', 'AWFUL!')
So your expression in Studio should read:
"concat('XPath ','is ', '"+context.emotion,String.class + "')"
Note that I have added an additional set of single quotes around the AWFUL that is being retrieved from the context.