on ‎2008 Feb 04 5:20 PM
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
Request clarification before answering.
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 (&) else you will face conversion errors.
Regards,
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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;' );
instr = instr.replace( '>', '&gt;' );
instr = instr.replace( '<', '&lt;' );
instr = instr.replace( '\"', '&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
You should not use these lines of code:
instr = instr.replace( '>', '>' );instr = instr.replace( '<'<' );instr = instr.replace( '\"', '"' );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
| User | Count |
|---|---|
| 9 | |
| 5 | |
| 4 | |
| 4 | |
| 3 | |
| 3 | |
| 2 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.