XML generation: Use of CDATA versus escaping XML chars
We are consuming a web service. The operation we are using has a field that is defined as a String in the WSDL, and should contain a blob of XML. To fill this field we generate XML using a domain-to-XML mapping. We then use the resulting String as one of the parameters when calling the webservice. Mendix will escape the XML chars in this case, by using > and < . The system we're integrating with however only supports escaping by using the CDATA tag. Is there a way we can have Mendix use CDATA? We tried all four settings for feeding parameters to the request body. What's interesting, is that when we use the Custom request body type to create a body with CDATA tags, Mendix will replace this with an escaped XML string. So for instance: <parameter>bar</foo>]]></parameter> will be changed to: <parameter><foo>bar</foo></parameter> This behaviour makes me suspicious that Mendix does some processing on an XML request before it is sent over the line, to just replace any CDATA constructs with escaped XML. So to conclude, our question is this: How can we force Mendix to use the CDATA tag?
From a quick glance we do escape CDATA when using the Mapping or Advanced option, but not for the simple option. You could file a ticket for this.
Sebastiaan van den Broek
For future reference: we implemented our own Java action using a call to Core.callWebservice(...). In this way we were able to specify the contents of the request.
We did the following:
Create a FileDocument.
Fill it using a Domain-To-XML mapping
Use the CommunityCommons Java action "StringFromFile"
Change the returned String and add the following:
Use this $ReturnedString as the data in your webservice call