04-03-2024 6:33 PM - edited 04-04-2024 4:53 AM
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.
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 ==>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @ag3silaus,
Thank you for the response.
Same code with below syntax working.
replaceAll("\\x1A", "")
Hello @inturidevendra,
please use this def cleanedPayload = body.replaceAll(/[^\x00-\x7F]/, ""); in groovyscript
Best Regards,
Burak
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
80 | |
9 | |
9 | |
7 | |
7 | |
6 | |
6 | |
6 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.