Sorry, all, here is a more specific question:
The query is constructed at runtime and executed using the QueryProcessor command.
Query: replace node . with <a>main(){int i=0;}</a>
Execution error: Expecting '}' found ...
If I try to bind the replacement as a global parameter, the error message is: Single element, text, attribute, comment or pi expected as replace target.
The java code:
QueryProcessor query = new QueryProcessor("replace node . with $replacement", context);
query.bind("replacement", "<a>main(){int i=0;}</a>");
The problem with escpaing the curly braces (or wrapping all text content nodes and maybe attribute values, too) is the extra overhead which would decrease performance.