Forum Discussion

chris_selwyn's avatar
chris_selwyn
New Contributor
15 years ago

How do I get an escaped string rather than CDATA?

I am using the following snippet to set a value in a SOAP request to be an XML string as constructed by a groovy MarkupBuilder

def xml = xmlsw.toString()
log.info("xml = " + xml)

def xmlh = gu.getXmlHolder("TMProcessData#Request")
xmlh.namespaces["ns"]='http://www.tbsmobility.com/TMHost/20041006'
xmlh["//ns:Data"] = xml

However the ns:Data element in the final SOAP request has a CDATA in it rather than escaped XML (with < and >).
Is there a way I can cause the XML to be escaped rather than contained in a CDATA?

Chris
  • M_McDonald's avatar
    M_McDonald
    Super Contributor
    Try this:

    def xml = org.apache.commons.lang.StringEscapeUtils.escapeXml(xmlsw.toString())