Skip to Content
avatar image
Former Member

Carriage return after each row in XML file

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?

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

4 Answers

  • avatar image
    Former Member
    Aug 17, 2005 at 12:28 PM

    Hi,

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

    BR,

    Jürgen

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      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

  • Aug 17, 2005 at 01:04 PM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Aug 17, 2005 at 02:01 PM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Aug 17, 2005 at 07:53 PM

    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

    -->

    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

    Add comment
    10|10000 characters needed characters exceeded

    • 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);

      }

      }