Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

change XML after CALL FUNCTION 'SDIXML_DOM_TO_XML'

christoph_rhein1
Associate
Associate
0 Likes
513

Hi All,

i need a possibility to change a proper formed XML into something like this.

Example:

<PRESOL>

<DATE> 0521

<YEAR> 99

<CBAC> demo

<PASSWORD> DEMO

<ZIP> 22030

<CLASSCOD> B

<NAICS> 123456

</PRESOL>

Thanks,

Christoph

Hi All,

i need a possibility to change a proper formed XML into something like this.

Example:

<PRESOL>

<DATE> 0521

<YEAR> 99

<CBAC> demo

<PASSWORD> DEMO

<ZIP> 22030

<CLASSCOD> B

<NAICS> 123456

</PRESOL>

Thanks,

Christoph

1 REPLY 1
Read only

uwe_schieferstein
Active Contributor
0 Likes
395

Hello Christoph

I assume that you want to remove all closing XML tags from your XML except for the very last one. Since I do not think there is a standard function/class available for this kind of transformation, I would simply use a couple of string operations to get the result.

Instead of describing the procedure I send you a code sample (the logic should be straightforward):

*&---------------------------------------------------------------------*
*& Report  ZUS_SDN_XML_TRANSFORMATION
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  zus_sdn_xml_transformation.


DATA:
  gd_xml         TYPE string,
  gt_split       TYPE STANDARD TABLE OF string,
  gd_string      TYPE string,
  gd_string_sav  TYPE string,
  gd_offset      TYPE i.


START-OF-SELECTION.

* sample XML string
  CONCATENATE
    '<pre><code>'
    '<DATE> 0521 </DATE>'
    '<YEAR> 99 </YEAR>'
    '<CBAC> demo </CBAC>'
    '<PASSWORD> DEMO </PASSWORD>'
    '<ZIP> 22030 </ZIP>'
    '<CLASSCOD> B </CLASSCOD>'
    '<NAICS> 123456 </NAICS>'
    '</code></pre>'
    INTO gd_xml.

* Just to see the entire string...
  WRITE: / gd_xml.
  SKIP 1.


* Split XML string at closing-tag marker
  SPLIT gd_xml AT '</' INTO TABLE gt_split.

* Just to see what happened...
  LOOP AT gt_split INTO gd_string.
    WRITE: / gd_string.
  ENDLOOP.
  SKIP 1.


* Do the string operations...
  LOOP AT gt_split INTO gd_string.
    gd_string_sav = gd_string.

    AT FIRST.
      CONTINUE.
    ENDAT.

    AT LAST.
      CONCATENATE '<' gd_string_sav INTO gd_string.
      MODIFY gt_split FROM gd_string INDEX syst-tabix.
      CONTINUE.
    ENDAT.

    SEARCH gd_string FOR '>' IN CHARACTER MODE.
    IF ( syst-fdpos > 0 ).
      gd_offset = syst-fdpos + 1.
      gd_string = gd_string+gd_offset.

      MODIFY gt_split FROM gd_string INDEX syst-tabix.
    ENDIF.

  ENDLOOP.

* Just to see what happened...
  LOOP AT gt_split INTO gd_string.
    WRITE: / gd_string.
  ENDLOOP.
  SKIP 1.


END-OF-SELECTION.

Regards

Uwe