groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Keegan Witt <>
Subject Re: How to convert a Node object to an XML String without escaping CDATA nodes value ?
Date Thu, 06 Aug 2015 02:00:22 GMT
Maybe I'm misunderstanding your use case, but why are you manually forcing
CDATA into the node text?  If you're parsing then reading node value, it
will automatically handle the CDATA.  Is this maybe what you meant to do?

def parent = new XmlParser().parseText('''
parent.append(new Node(parent, 'child2', parent.child.text()))
def sw = new StringWriter()
new XmlNodePrinter(new IndentPrinter(sw, '', false)).print(parent)
== sw.toString()

It won't write it with CDATA, but remember that <![CDATA[you&me]]> is
identical to you&amp;me for any parser following the spec.


On Wed, Aug 5, 2015 at 4:00 AM, Jean-Christophe Dominguez <
> wrote:

> def nodeValue = '<![CDATA[you&me]]>'
> Node rootNode = new Node(null, 'parent', [:], nodeValue)
> rootNode.append(new Node(null, 'child', [:], nodeValue))
> println groovy.xml.XmlUtil.serialize(rootNode)

View raw message