cancel
Showing results for 
Search instead for 
Did you mean: 

How to deal with invalid XML character (Unicode: 0x1a)

Former Member
0 Kudos

Hi,

I have a File -> PI -> ECC scenario.

Every now and then i get an error in the mapping and the error is this:

<SAP:P2>com.sap.aii.utilxi.misc.api.BaseRuntimeException:</SAP:P2>

<SAP:P3>An invalid XML character (Unicode: 0x1a) was found</SAP:P3>

<SAP:P4>in the element content of the document.</SAP:P4>

The error is caused because the file i receive contains names with a unicode character.

I can only make it visible in Notepad. The little arrow in the name is what causes the error.

If i remove the little arrow from the name, the processing works fine.

So that is my description of the error.

I've been looking on scn and found some descriptions of the issue, but never a real solution.

Now it would be best of course not to send the unicode character in the first place but that is not feasible at the moment, so I am looking for ways to remove the character before the XML is created.

Are there ways to do this?

My thoughts go to "Run Operating System Command Before Message Processing"

Is that an option to remove the character? If so, what steps should i follow to achieve this?

Are there other options?

Regards

Robert

Accepted Solutions (0)

Answers (5)

Answers (5)

former_member190293
Active Contributor

Hi Robert!

You could try to use following java code to replace that character:

private String stripNonValidXMLCharacters(String in) {  
  
if (in == null || ("".equals(in))) return null;
  
StringBuffer out = new StringBuffer(in);
  
for (int i = 0; i < out.length(); i++) {
  
if(out.charAt(i) == 0x1a) {
  
out.setCharAt(i, '-');
  
}
  
}
  
return out.toString();
}


Regards, Evgeniy.

Former Member
0 Kudos

This message was moderated.

Former Member
0 Kudos

Hi,

First i tried to set the file encoding to UTF-16

But that did not solve my error.

Then i tried the advice on the module. I inserted the MessageTransformBean as follows:

Is that done correctly? If it is correct then it doesn't help either. If it is not correct, then please advice on how to do it proper.

Regards

Robert

Former Member
0 Kudos

Hi Robert,

have you tried to use a UDF with a java code that assigns that value to a string using the UTF-8 encoding?

cheers,

Edu

RaghuVamseedhar
Active Contributor
0 Kudos

Robert,

Module configuration is correct. As it did not work, please revert it.

Please implement Java Mapping (it will be simple, if you follow "How to create Java Mapping" posted above).

engswee
Active Contributor
0 Kudos

Hi Robert

Two things:

i) Sequence of MTB is incorrect. It should be before CallSapAdapter

ii) Module name is incorrect. It should be AF_Modules/MessageTransformBean as that is the JNDI name in the server. Refer SAP library below.

Inserting MessageTransformBean in Module Processor -  Adding Modules to the Module Processor - SAP ...

You can also always check what is the correct name to use for a module by checking in the JNDI Browser of NWA - example shown in Step 1 of the following article.

Rgds

Eng Swee

Former Member
0 Kudos

Hi Eng Swee,

Thx for pointing out the correct way to implement the MessageTransformBean.

Unfortunately it didn't help me in getting rid of the message mapping error for that Unicode character.

So i guess i'll try the Java Mapping now.

First time to do that for me, but i guess i can do as was described in the link.

Regards

Robert

Former Member
0 Kudos

Hi Robert,

try something simple like

String outvalue = new String(invalue, "UTF-8");

return outvalue;

or something similar, just to parse the value you need.

Cheers,

Edu

Former Member
0 Kudos

Hi Robert,

have you tried to change file encoding?

I had a similar problem and I solved it setting file encoding as UTF-16, that manage UNICODE characters.

Fabio

RaghuVamseedhar
Active Contributor
0 Kudos

Hi Robert,

On second thought. After seeing "Fabio" response, I am updating my response.


It might be an encoding issue. Please try MessageTransformationBean: Transfer.ContentType = text/xml;charset="cp1252" OR utf-8.

More options / information

OR

Best solution is to request source system to send a well-formed XML (the XML which is failing in message mapping is not well-formed). If it is not possible to change the source program, please follow below solution.

In Java mapping .replaceAll("&", "&amp;") OR .replaceAll("&#26;", "") //removing that substitute. FYI. Unicode character table