How to append Carriage Return in the end of each tag of xml file


SAP PI Interview Questions and SAP PI Tutorials

SAP PI Interview Questions and SAP PI Tutorials

How to append Carriage Return in the end of each tag of xml file

Purpose

Purpose of this web log is to give a solution to the above mentioned title and also this is a frequently occurring question in SDN XI forum.

Introduction

This is a frequently occurring question these days in SDN XI forums, How to append a carriage return after some place and after end of tag of xml or some string. So I tried to give solution in generic way b y writing a simple UDF.

Here is the input structure I am using and treating this as and input to the UDF as xmlString.

ToveJaniReminderDon’t forget me this weekend!

Output we want

SAP PI Interview Questions and SAP PI Tutorials

SAP PI Interview Questions and SAP PI Tutorials

Tove

Jani

Reminder

Don’t forget me this weekend!

UDF for this

public String AddNewLineinEndofXMLTag(String xmlString,Container container){

//write your code here

String res = “”;

int flag = 0;

for(int i = 0;i

{

if(xmlString.charAt ==’<')

{

flag = 1;

res = res + xmlString.charAt ;

}

else

{

if(xmlString.charAt ==’>’)

{

flag = 0;

res = res +xmlString.charAt + “\n”;

}

else

{

res = res +xmlString.charAt ;

}

}

}

return res;

}

I hope, it will help many people to solve their purpose. You can also customized it and use it with some other requirements as well as with similar kind of scenarios.

SAP PI Interview Questions and SAP PI Tutorials

SAP PI Interview Questions and SAP PI Tutorials

Share this:
Share this page via Email Share this page via Stumble Upon Share this page via Digg this Share this page via Facebook Share this page via Twitter
en.pdf24.org    Send article as PDF   
This entry was posted in file2file senario, idoc senario step by step, jdbc2 jdbc sap xi senario, sap basis tutorials, sap pi 7.0 training, sap pi 7.1 tutorials. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *