Using XQuery (BaseX implementation), I need to process a set of XML records that may contain pairs of curly brackets within element text (eg, <a>Abc {de} fg</a>
). Right now, I am preprocessing the records outside of XQuery to ensure that these characters have been escaped as double brackets ( <a>Abc {{de}} fg</a>
).
Is there a standard way to escape these characters within XQuery in order to prevent them from being executed as an expression?
If you want to embed arbitrary UTF-8 encoded XML input in your query, you can use the XQuery 3.1 string constructor and fn:parse-xml
:
let $string := ``[<a>Abc {de} fg</a>]``
return fn:parse-xml($string)
The only thing you should ensure is that your XML string does not contain the characters ]``
.
In general, the safest way is to save your input in external files (or in a database) and address it via fn:doc
, fn:collection
, fetch:xml
, db:open
, etc.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.