cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

JSON to XML Cloud Integration raises error "Invalid white space character"

MohanI1984
Participant
0 Kudos
2,861

JSON to XML Converter in SAP Cloud Integration raises error "Invalid white space character"
SAP Techs, 

 3068804 - JSON to XML Converter in SAP Cloud Integration raises error "Invalid white space character... - explains the following error "com.ctc.wstx.exc.WstxIOException: Invalid white space character (0x11) in text to output (in xml 1.1, could output as a character entity)" can be addressed by using script or manual. 

 Help needed to address this using groovy/Java script to replace invalid white space character with space. 

Example input:  01,022xxxx20,Devendra,xasdas

Very last character "" is invalid white space character. 

 

 

<p>Example input: 01,022xxxx20,Devendra,asdasdfa</p>

 

 

Very last character "" is invalid white space character. 

Accepted Solutions (1)

Accepted Solutions (1)

ag3silaus
Participant
0 Kudos

Hello  @MohanI1984 ,

I'm not entirely sure if I understand correctly, but I believe you're asking if you need to remove white spaces from your payload. Is that correct? This is really easy with groovyscript you can also add this code to delete non ASCII characters.

import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
import groovy.json.JsonSlurper

def Message processData(Message message) {
//Body
def body = message.getBody(java.lang.String) as String;
def cleanedPayload = body.replaceAll(/[\s\u4E00-\u9FA5]/, "");
message.setBody(cleanedPayload);

return message;
}

 

This is the Output ==>

ag3silaus_0-1712192755923.png

 

 

MohanI1984
Participant
0 Kudos

Hello @ag3silaus,

  Thank you for the response.  

   Same code with below syntax working. 

 

 

 replaceAll("\\x1A", "")

 

 

 

 

  

Answers (2)

Answers (2)

ag3silaus
Participant
0 Kudos

Hello @MohanI1984,

please use this  def cleanedPayload = body.replaceAll(/[^\x00-\x7F]/, ""); in groovyscript

 

ag3silaus_0-1712246522060.pngag3silaus_1-1712246543746.png

 

Best Regards,

Burak

Joel_B
Explorer
0 Kudos

Another option to consider is using the XmlUtil library's escapeXml method:

fieldValue = groovy.xml.XmlUtil.escapeXml(fieldValue);

 The above will not only escape white space, but will escape any other characters which can be problematic for XML parsing.