cancel
Showing results for 
Search instead for 
Did you mean: 

Remove newline after XML declaration

0 Kudos

Hello,

We have an IDOC to XML scenario with a graphical mapping. PI is putting a newline after the XML declaration after transformation (please refer to the attachment)

Is it possible to remove this newline without using any custom module? I would prefer to handle it using standard modules or UDFs.

I have read the possibility of using an XSLT mapping but would like to avoid that if possible. Please suggest if any pointers.

Thanks

Justin

Accepted Solutions (0)

Answers (2)

Answers (2)

markangelo_dihiansan
Active Contributor
0 Kudos

Hi Justin,

Try viewing your output payload using page source. If you do not see a newline, it is just the xml parser that adds it a.k.a pretty print.

Regards,

Mark

0 Kudos

Thanks for the reply, yes I had checked it from page source only (without applying pretty print).

The standard format looks like the XML declaration will always come in one line and remaining payload in the next line.

vinaymittal
Contributor
0 Kudos

Its not possible by a udf because udf can work on the source structure while i guess you need to remove the XML declaration after the mapping is over in the target structure....for that you need to use either XSLT/Java mapping or standard function modules

Java mapping code

import java.io.InputStream;

import java.io.OutputStream;

import java.util.Map;

import java.util.HashMap;

import java.io.IOException;

import java.io.FileReader;

import java.io.BufferedReader;

import java.io.*;

 

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 RemoveNamespace extends AbstractTransformation

{

   

  public void transform(TransformationInput in, TransformationOutput out) throws StreamTransformationException

  {

       

    try {

     

   BufferedReader reader = new BufferedReader(new InputStreamReader(in.getInputPayload().getInputStream()));

   String line;

        while ((line = reader.readLine()) != null) {

            out.append(line);

        }

  //removing namespace in the string we have

  /*<?xml version="1.0" encoding="UTF-8"?> length is 38 then nl i.e 39

  */

  

  line = line.substring(line.indexOf(0,38)+line.substring(line.indexOf(39,line.length());

           

  out.getOutputPayload().getOutputStream().write(line.getBytes("UTF-8")); //writing to output

        }

  catch (Exception e)

  {

        e.printStackTrace();

         }

  

  }

      

}

0 Kudos

Thanks a lot for the response and the code, I am trying to avoid a java mapping if possible . Please let me know if you have an XSLT mapping for same.