on 02-01-2012 10:30 AM
Hello,
I have a requirement to read the XML file as the input and generate the same XML at the output with filename based on the content but issue is output xml file contains '?' as the first character before <?xml..> because of which it is failing in the target system. Please help me in understanding from where this additional '?' is coming and how to get rid of this.
Appreciate your response
Thanks,
Jitesh
Dear Jitesh
If your end sysytem is not expecting an '?' in the xml then probably they are not using a standard XML which accepts a header like this:
<?xml version="1.0" encoding="UTF-8"?>
If your end system donot want this then you may need to replace with a format (CSS Styleshet etc)
If that is the case you can use Java Mapping or XSLT to create the desired structure.
Sourabh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Jitesh,
Not sure on why you are getting a extra '?' at beginning of xml. If u wanna get rid of it use this java mapping code as last mapping just before your file gets written to output.
For PI 7.1 and above
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Map;
import com.sap.aii.mapping.api.AbstractTransformation;
import com.sap.aii.mapping.api.StreamTransformationException;
import com.sap.aii.mapping.api.TransformationInput;
import com.sap.aii.mapping.api.TransformationOutput;
public class RemoveFirstChar extends AbstractTransformation {
/**
* @param args
*/
public void execute(InputStream in, OutputStream out)
throws StreamTransformationException {
// TODO Auto-generated method stub
try
{
byte b[]=new byte[in.available()];
String encoding="UTF-8";
in.read(b);
String inputXML=new String(b);
inputXML=inputXML.substring(inputXML.indexOf('<'));
out.write(inputXML.getBytes(encoding));
}
catch(Exception e)
{
throw new StreamTransformationException(e.getCause().toString());
}
}
public void setParameter(Map arg0) {
// TODO Auto-generated method stub
}
public static void main(String[] args) {
// TODO Auto-generated method stub
try{
RemoveFirstChar genFormat=new RemoveFirstChar();
FileInputStream in=new FileInputStream("C:\\Apps\\my folder\\sdn\\qmark.xml");
FileOutputStream out=new FileOutputStream("C:\\Apps\\my folder\\sdn\\qmark1.xml");
genFormat.execute(in,out);
}
catch(Exception e)
{
e.printStackTrace();
}
}
public void transform(TransformationInput arg0, TransformationOutput arg1)
throws StreamTransformationException {
this.execute(arg0.getInputPayload().getInputStream(), arg1.getOutputPayload().getOutputStream());
}
}
Hope this solves your problem.
Regards
Anupam
Edited by: anupamsap on Feb 1, 2012 6:47 PM
Hi Jitesh,
Here is the java mapping code for PI 7.0 and below versions
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Map;
import com.sap.aii.mapping.api.StreamTransformation;
import com.sap.aii.mapping.api.StreamTransformationException;
public class RemoveFirstChar implements StreamTransformation {
/**
* @param args
*/
public void execute(InputStream in, OutputStream out)
throws StreamTransformationException {
// TODO Auto-generated method stub
try
{
byte b[]=new byte[in.available()];
String encoding="UTF-8";
in.read(b);
String inputXML=new String(b);
inputXML=inputXML.substring(inputXML.indexOf('<'));
out.write(inputXML.getBytes(encoding));
}
catch(Exception e)
{
throw new StreamTransformationException(e.getCause().toString());
}
}
public void setParameter(Map arg0) {
// TODO Auto-generated method stub
}
public static void main(String[] args) {
// TODO Auto-generated method stub
try{
RemoveFirstChar genFormat=new RemoveFirstChar();
FileInputStream in=new FileInputStream("C:\\Apps\\my folder\\sdn\\qmark.xml");
FileOutputStream out=new FileOutputStream("C:\\Apps\\my folder\\sdn\\qmark1.xml");
genFormat.execute(in,out);
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
Regards
Anupam
I assume you have a mapping where you set the ASMA ? What kind of mapping is it ?
Do you have any kind of content conversion ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
86 | |
10 | |
10 | |
9 | |
7 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.