Transforming escaped XML text into CDATA sections

Kondamne

New Member
I'm looking to replace escaped XML sections with CDATA blocks, mainly to improve the readability of XML that unfortunately has to be read by a human.\[code\]// Inputdef xml = '''<search> <search-query> <nested/< <xml/< </search-query></search>'''def search = new XmlParser().parseText(xml)def query = search."search-query"query.replaceNode() { "search-query"() { // TODO how can I add a CDATA section here? //yieldUnescaped("<![CDATA[${query.text()}]]>") }}new XmlNodePrinter(preserveWhitespace:true).print(search)// Expected'''<search> <search-query> <![CDATA[<nested/> <xml/>]]> </search-query></search>'''\[/code\]
  • Performance is not important
  • I want to be able to use CDATA on only certain elements
 
Back
Top