cancel
Showing results for 
Search instead for 
Did you mean: 

XML to XML Scenario

Former Member
0 Kudos

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

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

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

Former Member
0 Kudos

Hi Sourabh,

I get something like this in my output file

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

One additional ? before XML tag

Thanks,

Jitesh

anupam_ghosh2
Active Contributor
0 Kudos

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

anupam_ghosh2
Active Contributor
0 Kudos

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

Former Member
0 Kudos

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 ?