cancel
Showing results for 
Search instead for 
Did you mean: 

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

inturidevendra
Participant
0 Kudos

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. 

Ivan-Mirisola
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi @inturidevendra,

Can you post the payload you are trying to send to the converter as a "code sample"  container here (there is an icon under the additional tools accessible via the '...' button on the toolbar.

Also, could you also share a screenshot of the iFlow where the issue is happening?

Best regards,
Ivan

inturidevendra
Participant
0 Kudos

@Ivan-Mirisola,

  Thank you for the response. 

 Screenshot of the iFlow where the issue is happening

inturidevendra_0-1712185192195.png

Add a groovy script to change the payload to remove the Unidentified characters with space. 

 

import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
def Message processData(Message message) {
    def body = message.getBody(java.lang.String) as String;
    body = body.replaceAll("\\x1A", "") 
    message.setBody(modifiedBody.getBytes())
     }
    return message;
}

 

Payload. 

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

Please let me know if you need any more information. 

 

 

Ivan-Mirisola
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi @inturidevendra,

Could you please paste the payload as 'code'. You've pasted as text and it looses all special characters here. 

If it is pasted like 'code' it retains its format and any other characters. You could choose whatever language you like - it really doesn't matter. 

Best regards,
Ivan 

inturidevendra
Participant
0 Kudos
@Ivan-Mirisola, Updated my post. Can you please check.

Accepted Solutions (1)

Accepted Solutions (1)

ag3silaus
Participant
0 Kudos

Hello  @inturidevendra ,

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

 

 

inturidevendra
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 @inturidevendra,

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.