cancel
Showing results for 
Search instead for 
Did you mean: 

Target XML

Former Member
0 Kudos
70

Could anyone please let me know how to remove the XML header <?xml version="1.0" encoding="UTF-8" ?>

- <ns0:MT_Ack_Delivery_Inbound xmlns:ns0="urn:commscope.com/ALUespares/AckDelivery">

My trading partner doesn't require the XML header in the file that we are sending to them.

Actually he only want his xml header as mentioned below

<?xml version="1.0"?>

instead of the one which is shown below

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

- <ns0:MT_Ack_Delivery_Inbound xmlns:ns0="urn:commscope.com/ALUespares/AckDelivery">

Can any one please help me out of this

Accepted Solutions (1)

Accepted Solutions (1)

anupam_ghosh2
Active Contributor
0 Kudos

Hi ,

You need to add this java mapping code after your message mapping in the same interface mapping or operational mapping.

No need to change your existing message mapping. Let it remain as it is, just need to add this code after message mapping.

I tried with other mappings such as XSLT but could not achieve any results. Hence I feel only solution to your problem (other than writing adapter module) is java mapping.

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 RemoveEncodingName 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="<?xml version=\"1.0\" ?>"+inputXML.substring(inputXML.indexOf('>')+1,inputXML.length());
			out.write(inputXML.getBytes(encoding));
		}	
		catch(Exception e)
		{
			e.printStackTrace();
		}	
		
	}

	public void setParameter(Map arg0) {
		// TODO Auto-generated method stub
		
	}
	public void transform(TransformationInput arg0, TransformationOutput arg1)
			throws StreamTransformationException {
	 this.execute(arg0.getInputPayload().getInputStream(), arg1.getOutputPayload().getOutputStream());
		
	}
}

For PI 7.0


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 RemoveEncodingName 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="<?xml version=\"1.0\" ?>"+inputXML.substring(inputXML.indexOf('>')+1,inputXML.length());
			out.write(inputXML.getBytes(encoding));
		}	
		catch(Exception e)
		{
			e.printStackTrace();
		}	
		
	}

	public void setParameter(Map arg0) {
		// TODO Auto-generated method stub
		
	}
}

if you need help in java mapping you can consult this link which shows steps to compile and upload java mapping codes to PI server

http://wiki.sdn.sap.com/wiki/display/XI/BeginnersguidetoJavamappingusingDOMparserinSAPXI

Regards

Anupam

Former Member
0 Kudos

thanks very much for your help Anupam, can u please also tell me where exactly i should add this code.

anupam_ghosh2
Active Contributor
0 Kudos

Hi,

you have not mentioned the version of PI you are working. Thus I am letting you know in generic way.

First you need to compile this java program and import the jar file into the PI server. The steps to do this is explained in the link i provided in my last post. you have to import the jar file to imported archive. Use proper external jar file to compile the code according to version of PI server you are working. Ask for proper external jar files from your colleagues or in SDN search for it.

you can consult this link http://wiki.sdn.sap.com/wiki/display/XI/WheretogetthelibrariesforXI+development

This is important since you need to compile the code with proper jar file and proper java version as per your PI server.

After import is complete, go into the interface or operation mapping where you have the old message mapping.

Here you import the java class file from imported archive. save and activate.

Regards

Anupam

Former Member
0 Kudos

Thanks very much Anupam,

The version iam using is PI7.1

Answers (1)

Answers (1)

Former Member
0 Kudos

HI

<?xml version="1.0"?>

It can be done easily with Java mapping by just taking the input xml as string and then removing the encoding part from the string

please refer below blog:

You can use the following code if your PI version is 7.1

import java.io.IOException;

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 Test extends AbstractTransformation {

@SuppressWarnings("null")

public void transform(TransformationInput transformationInput,

TransformationOutput transformationOutput)

throws StreamTransformationException {

getTrace().addDebugMessage("Entered transform method");

InputStream in = transformationInput.getInputPayload().getInputStream();

OutputStream out = transformationOutput.getOutputPayload()

.getOutputStream();

try {

byte[] b = new bytehttp://in.available();

in.read(b);

String req = new String(b);

req = req.replaceAll("<?xml version="1.0" encoding="UTF-8"?>" , "<?xml version="1.0"?>" );

out.write(req.getBytes());

out.flush();

}

catch (IOException ioe) {

getTrace().addWarning(

"Error While prerforming Java Transformation"

+ ioe.getMessage());

throw new StreamTransformationException(

"Error While prerforming Java Transformation"

+ ioe.getMessage(), ioe);

}

}

}

thanks,

Former Member
0 Kudos

Hello thanks for your help,

but i have already done Message Mapping and every thing, is there any way to just edit that part without doing complete mapping again.

Former Member
0 Kudos

hi,

as per my knowledge that is only possiable with mapping.

thanks,

baskar_gopalakrishnan2
Active Contributor
0 Kudos

Why your client wants to edit that part? encoding or codepage tag is default and will not harm your processing on both side. If you want just use XSLT mapping to remove it. XSLT mapping is pretty simple in this case.

Former Member
0 Kudos

post deleted

Edited by: AmitSri on Dec 17, 2011 4:20 PM