cancel
Showing results for 
Search instead for 
Did you mean: 

Carriage return after each row in XML file

Former Member
0 Kudos

Hi all,

we need after each closing tag in a XML file a carriage return. We use the file adapter without file content conversion.

e.g.:

The output should be:

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

- <TF_BORDERO>

<TF_VERSION>02.51</TF_VERSION>

<TF_UPDATE>I</TF_UPDATE>

<TF_CODEPAGE>UTF-8</TF_CODEPAGE>

<ADR_ADRID>1006000061</ADR_ADRID>

<TF_ERSTDAT>20050817</TF_ERSTDAT>

<TF_FLAG>P</TF_FLAG>

But it is:

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

<TF_BORDERO><TF_VERSION>02.51</TF_VERSION><TF_UPDATE>I</TF_UPDATE><TF_CODEPAGE>UTF-8</TF_CODEPAGE><ADR_ADRID>1006000061</ADR_ADRID><TF_ERSTDAT>20050817</TF_ERSTDAT><TF_FLAG>P</TF_FLAG>

Is there any possibility with using a module with parameter settings or something else?

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

Hi Thomas,

You could use an Identity Transform XSLT Map and specify that it indents the XML. This will add a carriage return after each line. Here's the XSLT:

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

<!--

XI Mapping StyleSheet

Name: IdentityTransform.xsl

-->

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="xml" indent="yes"/>

<!-- Identity Transform

Copy the source XML to the output without any changes -->

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

<xsl:copy>

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

</xsl:copy>

</xsl:template>

</xsl:stylesheet>

Why do you need to do this? XML Parsers should be able to handle the file either way.

Thanks,

Jesse

Former Member
0 Kudos

Hi Jesse,

thank you for the answer. I will add the code.

You are rigth XML Parsers should be able to handle the file either way. I really don't know why they want it on this structure!

Thomas

Werner_Magerl
Participant
0 Kudos

Hi,

I had the same problem while sending IDOCs through the email adapter.

One partner had also trouble in processing such messages without CR, because in a email server or somewhere between the email adpater and the receiver the line is truncated suddenly with a CR, and this occurs somewhere.

In this case the XML is invalid then.

We solved the problem with t simple JAVA coding like the XSL coding.

Now I add this JAVA coding for all outgoing message to avoid this problems.

best regards

Werner

Former Member
0 Kudos

Hi Werner,

can you send this Java code?

Thanks in advance

Thomas

Werner_Magerl
Participant
0 Kudos

Hello Thomas,

sorry for the late answer.

Here is the part of the coding.

There is nothing special about conversion,

I just call the parser and return the XML stream back.

The parser itself provides this conversion with CR/LF.

I think it is not the best way to do this, but it works fine and it was very easy.

best regards

Werner

public void execute(InputStream in, OutputStream out) throws StreamTransformationException

{

try

{

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

factory.setNamespaceAware(true);

DocumentBuilder builder = factory.newDocumentBuilder();

Document doc = builder.parse(in);

TransformerFactory tFactory = TransformerFactory.newInstance();

Transformer t = tFactory.newTransformer();

t.setOutputProperty(OutputKeys.INDENT, "yes");

t.transform(new DOMSource(doc), new StreamResult(out));

}

catch(Exception e)

{

e.printStackTrace();

throw new StreamTransformationException("Mapping Error!", e);

}

}

Former Member
0 Kudos

Your XML looks wrong to me because it does not have a closing tag for TF_BORDERO element.

Check your XML file. May be you did not post the entire XML.

One other thing, it is only a represention to see each tag in a line, if you use XMLSpy or any other XML tool, you can see them the way you are expecting.

regards

SKM

Former Member
0 Kudos

Hi, thanks

you are rigth.

I only copied a small part using XMLSpy (with carriage return) and the second one with the "real" view by using notepad.

So i need really a carriage return after every closing tag. The missing closing tag for TF_BORDERO is only a copy error.

regards

Thomas

Former Member
0 Kudos

In the XMLSpy there is a pretty print button. Use that. The way you are expecting to see is a view only.

regards

SKM

stefan_grube
Active Contributor
0 Kudos

Hi Thomas,

there is no standard to add the carriage return in xml.

You have to use Java/Abap Mapping or XSLT mapping to create the CR characters.

Regards

Stefan

Former Member
0 Kudos

Hi,

Have you tried to use text mode in your file adapter instead of binary?

BR,

Jürgen

Former Member
0 Kudos

Hi,

thanks for the answer but it

doesn't work. If i insert text mode, there is no carriage return and if i try to open the xml file with internet explorer, then i received an error.

Thomas