cancel
Showing results for 
Search instead for 
Did you mean: 

SAP PI 7.3.1 XML line break within node

GaryK
Explorer
0 Kudos

Good Morning All,

I've an issue with link breaks in XML. Basically, the scenario is IDoc (SAP) to File (XML 3rd Party System).

I've mapped a text field from the IDoc to the XML node (<comments>) .  The text data comes across with a delimiter !$! to indicate where a line break should occur within the <comment>  node in the XML

For example the text line comes across in the IDoc as  line 1!$!This is Line 2!$! this one is line 3!$!  and within the xml file I need to the <comment> node to look like  <comment>line 1

                                   This is line 2

                                   this one is line 3</comment>

We need this for formatting in the 3rd party system. I've tried various replaces etc. but the new line never seems to get recognized. 

Any help with this would be very much appreciated.

Thanks

G

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Use OS specific new line character by using System.getProperty("line.separator"😞

Here is complete code:
UDF with Context option

Parameters:String var[], ResultList result)

String temp[] = var[0].split("!$!");

for(int i = 0; i < temp.length; i++)

{

     result.addValue(temp[i] + System.getProperty("line.separator"));

}

Check it should work, I have not tested...

--Divyesh

   

GaryK
Explorer
0 Kudos

Hello to you Divyesh,

Thanks so much for the UDF logic.  It works to a point. it splits the first line but nothing else so:

<comment> line 1!$!This is Line 2!$! this one is line 3!$!  </comment>


becomes


<comment>line 1

</comment>


do i needs to change some logic to ensure the rest of the line is considered ?


thanks again

Gary

EDIT - When I check the result of the mapping using 'Display Queue'  I can see it working however in the resulting XML just the first line is displayed as above

Former Member
0 Kudos

Hello,

I am just altering Divyesh's code

Try this:

String output = "";

String temp[] = var[0].split("!$!");

for(int i = 0; i < temp.length; i++)

{

   output= output + temp[i] + System.getProperty("line.separator");

}

result.addValue(output);


Thanks

Amit Srivastava

GaryK
Explorer
0 Kudos

Hi Amit,

That worked great.  Thanks for taking the time.

Divyesh - thank you for your help also.

It's greatly appreaciated guys.

Thanks

Gary

Answers (1)

Answers (1)

javier_alcubilla
Contributor
0 Kudos

Hi Gary

Have you tried with an UDF?

In any case, I think that you have to know which code/character is used in target system to do a carriage return

Regards

Javi

GaryK
Explorer
0 Kudos

Hi Javier,

Thanks for replying. I've new in PI so have not looked at a UDF specifically. I require an ascii carriage return basically. 

Thanks

Gary