Tuesday 8 September 2015

wso2 dynamic xpath expression evaluation

Hi All,
                Welcome to a new post for today, this is not a major problem some might have figured it already , but this is not well documented i guess.


Suppose you want to evaluate a xpath expression dynamically in wso2

for eg.

if you read an expression from your database like it has value "xpathexpression"

how to evaluate this dynamically and store in property or use any where else?


suppose you want to evaluate the expression retrieved from db.

first you can create a property to create your xpath function

<property name="xpathexpr" expression="fn:concat('//',get-property('xpathexpression'))" scope="default" type="STRING"/>

Now having created the function using concatenation you can run the following expression

<property name="xpatheval" expression="evaluate($ctx:xpathexpr)" scope="default" type="STRING"/>

and that's it you can log the property to check if it evaluates correctly :)

No comments:

Post a Comment