Here is a code To remove empty umwanted tags from your mapping.
After completing the graphical mapping use this structure independent code to remove empty tags from your structure as a second step.
Compile it and do not forget to include .project and .class files in the folder structure.
//Code Begins
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.Map;
import com.sap.aii.mapping.api.AbstractTrace;
import com.sap.aii.mapping.api.StreamTransformation;
import com.sap.aii.mapping.api.StreamTransformationConstants;
import com.sap.aii.mapping.api.StreamTransformationException;
public class RemoveEmptyTags implements
StreamTransformation
{
private Map param = null;
//private AbstractTrace trace = null;
public static void main(String args[])
{
try
{
System.out.println("Start...");
InputStream in = new FileInputStream(new File(
"ip1.xml"));
OutputStream out = new FileOutputStream(
new File(
"op.xml"));
RemoveEmptyTags myMapping = new RemoveEmptyTags();
myMapping.execute(in, out);
System.out.println("End...");
}
catch (Exception e)
{
System.out.println("ERROR IS :" + e.getMessage());
}
}
public void execute(InputStream arg0, OutputStream arg1)
throws StreamTransformationException
{
// trace = (AbstractTrace)param.get(
// StreamTransformationConstants.MAPPING_TRACE );
try
{
//trace.addInfo("Mapping to replace empty node started ...");
String sb = null;
byte[] b = new byte[80000];
for (int n; (n = arg0.read(b)) != -1;)
{
sb = new String(b, 0, n);
}
//sb = sb.replaceAll("<!--[A-Za-z0-9]*-->", "");
for(int i =0;i<4;i++)
{
sb = sb.replaceAll("<[A-Za-z0-9]*></[A-Za-z0-9]*>", "");
sb = sb.replaceAll("<[A-Za-z0-9]*/>", "");
}
arg1.write(sb.getBytes());
sb =null;
}
catch (IOException e)
{
throw new StreamTransformationException("I/O exception", e);
}
catch (NullPointerException th)
{
throw new StreamTransformationException(th.getMessage(), th);
}
catch (Exception e)
{
throw new StreamTransformationException("Mapping failed", e);
}
}
public void setParameter(Map param)
{
if (param == null) {
this.param = new HashMap();
}
}
}
//Code Ends