Skip to Content
author's profile photo Former Member
Former Member

Closing tag in xml transformation

Hi experts,

I have the following ABAP code:

[...]

  • ABAP itab to XML string

CALL TRANSFORMATION id SOURCE data = ti_stocks[]

RESULT XML ps_output.

[...]

The result in ps_output should be an xml like this

<?xml version="1.0" encoding="utf-16" ?>

http://www.sap.com/abapxml" version="1.0">

<asx:values>

<DATA>

<ZTABLE_STO>

<FIELD1 /> ABC</FIELD1>

<FIELD2 />0300</FIELD2>

<FIELD3 />1</FIELD3>

</ZTABLE_STO>

etc.

However, if my internal table ti_stocks contains the field1 with an empty value then the xml is incorrect without its corresponding closing tag:

<?xml version="1.0" encoding="utf-16" ?>

http://www.sap.com/abapxml" version="1.0">

<asx:values>

<DATA>

<ZTABLE_STO>

<FIELD1 />

<FIELD2 />0300</FIELD2>

<FIELD3 />1</FIELD3>

</ZTABLE_STO>

etc.

How can I resolve this problem? I would like to have an open tag and a closing tag for every field.

FIELD1 is a char type field.

Thank you,

Oscar

Edited by: Oscar Arranz on Jan 26, 2012 2:46 PM

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Jan 26, 2012 at 02:15 PM

    Hi,

    Since Field1is a char type, assign blank space explicitly if it has blank value.

    Then transform it into XML and check it out.

    Cheers,

    Raja.D

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jan 27, 2012 at 11:45 AM

    I don't see the problem.

    <tag></tag>

    is technically the same as

    <tag />

    Add a comment
    10|10000 characters needed characters exceeded

    • Hello everyone, sorry for my english, I had the same requeriment for the end tag, the simple transformation give this result <xxx/> when the value was empty, and I did something similar to Oscar,

      i did the simple transformation and the result whas and xstring, i used a function to pass it to string, and then I make a replacement.

      here is some code:

      * Genera XML

      data: xml_xstring type xstring.

      data: w_xml type string.


      data: ixml type ref to if_ixml,

      streamfactory type ref to if_ixml_stream_factory,

      encoding type ref to if_ixml_encoding,

      ixml_ostream type ref to if_ixml_ostream.

      data: resstream type ref to if_ixml_ostream.

      ****Create an instance of the Ixml Processor

      ixml = cl_ixml=>create( ).

      * ****Create the Stream Factory

      streamfactory = ixml->create_stream_factory( ).

      * ****Create an Endcoding and Byte Order

      encoding = ixml->create_encoding( character_set = 'ISO-8859-1' byte_order = 0 ).

      * * ****Create the output stream with a pointer to our binary string

      ixml_ostream = streamfactory->create_ostream_xstring( xml_xstring ).

      * ****Set the Encoding into a stream

      ixml_ostream->set_encoding( encoding = encoding ).

      ****Call simple Transformation

      call transformation zdte_libros

      source zcaratula = x_doc

      result xml ixml_ostream.

      *From xstring to string.

      call function 'HR_RU_CONVERT_HEX_TO_STRING'

      exporting

      xstring = xml_xstring

      importing

      cstring = w_xml.

      * <xxx/> to <xxx><xxx/>

      replace all occurrences of regex '<([^><\s]+)( [^><]+)?/>' in w_xml with '<$1$2></$1>'.

      Hope it helps someone with the same problem 😊.

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.