Skip to Content
Jun 24, 2015 at 10:40 AM

Need to remove XML indent from Target XML


Hi All,

I came again with strange issues.

I need to remove xml Indent (<?xml version="1.0" encoding="UTF-8"?>) for this I tried with Java and XSLT mapping both able to remove this indent.

But here is the catch , I can see there is no indent in Operation Mapping but when file is getting created indent is there.

Can anyone help me on the same.

Note :- I am using SAP SFTP adapter ( SAP PI 7.11)

Please find the code below , Both Code are working fine .. šŸ˜”


<xsl:stylesheet version="1.0" xmlns:xsl="">

<xsl:output method="xml" omit-xml-declaration="yes"/>

<xsl:template match="@* | node()">


<xsl:apply-templates select="@* | node()"/>




Java :-

public class NameSpaceReplace extends AbstractTransformation {

InputStream inputStream = null;

OutputStream outputStream = null;


* 1. Replace Namespaces.



public void transform(TransformationInput transformationInput, TransformationOutput transformationOutput) throws StreamTransformationException {

try {

//Getting input stream and output stream.

inputStream = transformationInput.getInputPayload().getInputStream();

outputStream = transformationOutput.getOutputPayload().getOutputStream();

//Reading input stream content into a String.

byte[] b = new byte[inputStream.available()];;

String strContent = new String(b);

// 1. Replace Namespaces.

strContent = strContent.replace('?','D');

strContent = strContent.replaceAll("<Dxml version=\"","");

strContent = strContent.replaceAll("1.0\"","");

strContent = strContent.replaceAll("encoding=\"","");

strContent = strContent.replaceAll("UTF-8\"","");

strContent = strContent.replaceAll("D>","");

strContent = strContent.trim();

//Write output to outputStream.


} catch (IOException ex) {


throw new StreamTransformationException("Can not read input stream.", ex);

} finally {

try {



} catch (IOException ex) {


throw new StreamTransformationException("Can not close input stream or output stream.", ex);





Warm Regards,