2006 Jul 24 4:07 PM
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
2006 Aug 16 4:15 AM
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
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |