Escaping Apostrophe in XPATH

0
In reference to this case : https://community.mendix.com/link/questions/106497   i would still like to understand on how to print single quote inside a xpath query. the part of the xpath query is a variable and this variable contains single quotes within the string . xpath does add single quotes at the beginning and end of the string.  When xpath parses the variable to form a query , it replaces all single quotes with ' so the final xpath query becomes : [contains(Roles,'Role1') or contains(Roles,'Role2')]  instead of [contains(Roles,'Role1’) or contains(Roles,’Role2')]  
asked
2 answers
0

I've had a similar issue when creating an xpath query from a string when we had to do so for a particular widget. What helped for us was to use triple quotes in the string, like this:

 

This fixed our issue and the xpath seems to be working properly. I'm not sure if this would work for your use case, but it might be worth a try.

answered
0

Another thing which may work, in case Eline's answer doesn't fit your usecase, is attempting to escape the characters. This is described here: https://docs.mendix.com/refguide/string-function-calls
I've copy pasted the specific part (with Q\ and E\) below.

 

answered