cancel
Showing results for 
Search instead for 
Did you mean: 

Special Chars in XML input

Former Member
0 Kudos

Hi Guru's,

I am doing a FIle(XML) to Proxy scenario. Unfortunately the file sent by 3rd party system contains some special chars like "&".

Here is what I get into XI. <Program>FY08 Pilsner - National Media & Fees</Program>. When I manually change it to <Program><![CDATA[FY08 Pilsner - National Media & Fees]]></Program> it works.

After reading some of the forum threads I came to know that we can do this using JAVA mapping before doing the actual graphical mapping. I need to what exactly I should be doing in JAVA mapping and I need some sample JAVA mapping code if somebody has already implemented this solution.

Thanks.

Srini Vaidyam

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Srinivas,

Payload is not valid XML. What is your File sender system character set use it in the File Adapter for conversion.

& should be escaped (&amp) else you will face conversion errors.

Regards,

Former Member
0 Kudos

Hi SriHari,

I cannot ask them to send the XML file in a different/correct format. All I can do is take it in and somehow change it using JAVA Mapping.

Can anbody help me in sharing some similar JAVA Code if you have faced similar problem.

Thanks.

Srini

Former Member
0 Kudos

The java mapping code will look something like:

public class FixEncoding implements StreamTransformation {

public void execute(InputStream in, OutputStream out)

throws StreamTransformationException {

String instr;

instr = parseIStreamToString(in);

instr = instr.replace( '&', '&amp;amp;' );

instr = instr.replace( '>', '&amp;gt;' );

instr = instr.replace( '<', '&amp;lt;' );

instr = instr.replace( '\"', '&amp;quot;' );

out.write(instr.getBytes());

}

public String parseIStreamToString(InputStream is) {

BufferedReader din = new BufferedReader(new InputStreamReader(is));

StringBuffer sb = new StringBuffer();

try {

String line = null;

while ((line = din.readLine()) != null) {

sb.append(line + "\n");

}

} catch (Exception ex) {

ex.getMessage();

} finally {

try {

is.close();

} catch (Exception ex) {

}

}

return sb.toString();

}

}

Note I have left out the includes and might need to handle some try/catches with error handling.

Regards,

Jason

Edited by: Jason Currey on Feb 5, 2008 1:28 AM

Edited by: Jason Currey on Feb 5, 2008 1:30 AM

Edited by: Jason Currey on Feb 5, 2008 1:31 AM

stefan_grube
Active Contributor
0 Kudos

You should not use these lines of code:

instr = instr.replace( '>', '&gt;' );
instr = instr.replace( '<'&lt;' );
instr = instr.replace( '\"', '&quot;' );

This would corrupt the XML.

The code must be more sophisticated, as you have to check, if an & amp; is already in your XML, then you would not change the &.

Regards

Stefan

Answers (10)

Answers (10)

ChadRichardson
Participant
0 Kudos

Have you tried an XSL mapping??? As long as you map the field itself to it's proxy counterpart and do not save it to a memory variable for manipulation later, I believe the XSL mapping would be the way to go. I know I've done something similiar for proxy to JDBC and proxy to file but haven't gone file to proxy. Just a thought.

Former Member
0 Kudos

I would suggest you do follow three things:

1.) Specify the character enconding at both sender and receiver side so that the file is successfully picked. The encoding must be in the xml declaration.

2.) Get the complete message (Main Window) in RWB and check, at which column i.e. (:main:, row:1, col:1) are you getting this error. Many times I attributed the error to special character but it turned out something else.

3.) Althogh, java mapping is an option but its not necessaily needed. (I tried a mapping with one field &&& and it worked OK).

But first confirm in trace that its & bothering you.

Regards,

AV.

Former Member
0 Kudos

Thanks for all the helpful answers. I awarded points for all those hints that were helpful.

Here is how I resolved it. I persued with the 3rd party who sent us the XML file to encode the 4 special characters. It was not that bad on their end to encode these special chars.

Thanks.

Srinivas Vaidyam

rodrigoalejandro_pertierr
Active Contributor
0 Kudos

hi,

we faced the same problem, we cange the encoding to UTF-8 and the special characters were added to RKCS tcode

also see it

Thanks

Rodrigo

rodrigoalejandro_pertierr
Active Contributor
0 Kudos

hi,we faced tghe same problem with & and #. to solve it, the encopndig was change to UTF-8 and the caracters was added to RKSC transaction.

do not reprocess the message, send it again.

Thanks

Rodrigo

Former Member
0 Kudos

Hi Srinivas,

For this give either &amp; or US-ASCII in FILE ENCODING in the file adapter.

Former Member
0 Kudos

Srinivas,

Jason's method would work, here is an alternative method of converting inputstream to string

try {

StringBuffer strbuffer = new StringBuffer();

byte[] b = new byte[4096];

for (int n;(n = in.read(b)) != -1;) {

strbuffer.append(new String(b, 0, n));

}

strXML = strbuffer.toString();

} catch (Exception e) {

System.out.println("Exception Occurred");

}

Thanks,

Anand

Edited by: Anand Gopinath on Feb 5, 2008 6:06 AM

rodrigoalejandro_pertierr
Active Contributor
0 Kudos

hi

go to TCODE RSKC. in text box, delete ALL_CAPITAL and add "&"

Thanks

Rodrigo

Former Member
0 Kudos

The payload looks like OK, it should not cause any problem.

(I am assuming that the node is xsd:string)

Can you paste the error in trace ?

Liang

Former Member
0 Kudos

Hi,

Change the encoding to ISO-8859-1 and then try.

Sarvesh

Former Member
0 Kudos

Sarvesh,

I tried that too. Still the same problem.

Thanks.

Srini

Former Member
0 Kudos

Then try to change "&" with "&amp" in mapping.

Former Member
0 Kudos

Hi Rodrigo,

I tried RSKC tcode and save the "&" as permitted character. Mapping still failed.

Sarvesh,

I tried to replace & with &amp. It did not work either.

Here is the error message

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>

- <!-- Request Message Mapping

-->

- <SAP:Error xmlns:SAP="http://sap.com/xi/XI/Message/30" xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/" SOAP:mustUnderstand="">

<SAP:Category>Application</SAP:Category>

<SAP:Code area="MAPPING">EXCEPTION_DURING_EXECUTE</SAP:Code>

<SAP:P1>com/sap/xi/tf/_PO_MCR_MM_</SAP:P1>

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

<SAP:P3>Fatal Error: com.sap.engine.lib.xml.parser.Parser~</SAP:P3>

<SAP:P4 />

<SAP:AdditionalText />

<SAP:ApplicationFaultMessage namespace="" />

<SAP:Stack>com.sap.aii.utilxi.misc.api.BaseRuntimeException thrown during application mapping com/sap/xi/tf/_PO_MCR_MM_: Fatal Error: com.sap.engine.lib.xml.parser.Parser~</SAP:Stack>

<SAP:Retry>M</SAP:Retry>

</SAP:Error>

Former Member
0 Kudos

Vaidyam,

I dont think it will create a problem. That should be fine. Can you paste the whole payload here.

Regards,

---Satish

Former Member
0 Kudos

The "&" create problem in my graphical mapping.

Here is the payload

<Report xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="file:///C:/Trandev50/models/MyModels/XSDFINAL.xsd"><Data>

<Row>

<Month>1</Month>

<Year>2008</Year>

<IncBrand>UR</IncBrand>

<MktArea></MktArea>

<MediaType>110</MediaType>

<PlanAmt>45704.5</PlanAmt>

<Program>FY08 Pilsner - National Media & Fees</Program>

</Row>

<Row>

<Month>2</Month>

<Year>2008</Year>

<IncBrand>UR</IncBrand>

<MktArea></MktArea>

<MediaType>110</MediaType>

<PlanAmt>25134.5</PlanAmt>

<Program>FY08 Pilsner - National Media & Fees</Program>

</Row>

<Row>

<Month>3</Month>

<Year>2008</Year>

<IncBrand>UR</IncBrand>

<MktArea></MktArea>

<MediaType>110</MediaType>

<PlanAmt>22316</PlanAmt>

<Program>FY08 Pilsner - National Media & Fees</Program>

</Row>

</Data>

</Report>