Search code examples
xpathxpath-3.1

How to generate a JSON string with XPath 3.1


I have some text in a node, for example:

<xml>&lt;Hello world "&amp;" foo bar&gt;</xml>

I would like to process string(/xml) and JSON-escape it so that the result would be something like:

"<Hello world \"&\" foo bar>"

How can I do it with XPath 3.1?


Solution

  • You can use serialize(string(xml), map{'method': 'json'})