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>
    <child><![CDATA[you&me]]></child>
</parent>
''')
parent.append(new Node(parent, 'child2', parent.child.text()))
def sw = new StringWriter()
new XmlNodePrinter(new IndentPrinter(sw, '', false)).print(parent)
assert
"<parent><child>you&amp;me</child><child2>you&amp;me</child2><child2>you&amp;me</child2></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.

-Keegan

On Wed, Aug 5, 2015 at 4:00 AM, Jean-Christophe Dominguez <jcd....@gmail.com
> 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)
>

Reply via email to