on 12-04-2015 8:45 AM
Hi,
I have an issue with a file which we do not receive as a valid xml.
A simplified version of the file looks like this:
<line><fieldx value="xxx"/><fieldy value="yyy"/></line>
<line><fieldx value="xxx"/><fieldy value="yyy"/></line>
<line><fieldx value="xxx"/><fieldy value="yyy"/></line>
All I need to make it a valid xml is a root node wrapped around it, like:
<message>
<line><fieldx value="xxx"/><fieldy value="yyy"/></line>
<line><fieldx value="xxx"/><fieldy value="yyy"/></line>
<line><fieldx value="xxx"/><fieldy value="yyy"/></line>
</message>
I have been struggling with xslt, but despite numerous examples, did not get it to work.
We still feel I should work with xslt, but how?
Any suggestions are more then welcome
Hi Henk,
Please do not use FCC in sender channel. Use dummy source and target Interfaces. Apply this java mapping code
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
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 ValidXML extends AbstractTransformation{
/**
* @param args
* @throws FileNotFoundException
* @throws StreamTransformationException
*/
@Override
public void transform(TransformationInput arg0, TransformationOutput arg1)
throws StreamTransformationException {
// TODO Auto-generated method stub
execute(arg0.getInputPayload().getInputStream(),arg1.getOutputPayload().getOutputStream());
}
public void execute(InputStream in, OutputStream out) throws StreamTransformationException
{
try
{
StringBuilder s = new StringBuilder();
byte[] b=new byte[in.available()];
if(in.read(b) >= 0) {
s = new StringBuilder(s.toString()+new String(b));
}
s= new StringBuilder(s.insert(0,"<message>"));
s= new StringBuilder(s.append("</message>"));
System.out.println(s);
out.write(s.toString().getBytes());
in.close();
out.close();
}
catch(Exception e)
{
e.printStackTrace();
throw new StreamTransformationException(e.getMessage());
}
}
}
Regards
Anupam
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Anupam,
I have applied this code in the Attributes and Methods section of the message mapping and it works perfectly.
Thanks for your help.
Regards,
Henk
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Henk,
Another alternative if you are using a file adapter is to create a shell script ( Defining Operating System Commands Before/After Processing - Advanced Adapter Engine - SAP Library) to add the two tags for the root node before processing.
Regards.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Henk
AFAIK, XSLT requires a valid XML as an input which you do not have. I think your only option would be to go for a Java mapping to add the root node to the payload.
Rgds
Eng Swee
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
85 | |
10 | |
9 | |
9 | |
6 | |
6 | |
6 | |
5 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.