on 2024 Jul 28 11:34 PM
There is an error in the XML Writer framework. When used, the XML files are created without an XML declaration. Even if the XML declaration is optional, this leads to incorrect behavior. The XML cannot be viewed as a structure in the debugger because the SAP debugger does not recognize the XML as such. The debugger can´t display an XML that creates an SAP class because an optional parameter is missing. It is not a good solution to simply assign the parameter. We made an example to show the effects:
" make XML with XML declaration
DATA writer_with_declaration TYPE REF TO if_sxml_writer.
DATA xml_with_declaration TYPE string.
writer_with_declaration = CAST if_sxml_writer( cl_sxml_string_writer=>create( encoding = CONV #( 'UTF-8' ) ) ). " <= XML declaration
writer_with_declaration->write_node( writer_with_declaration->new_open_element( name = 'test_tag' ) ) .
writer_with_declaration->write_node( writer_with_declaration->new_close_element( ) ).
DATA(conv_w_decl) = cl_abap_conv_in_ce=>create( input = CAST cl_sxml_string_writer( writer_with_declaration )->get_output( ) encoding = zif_lib_print_serializer=>c_encoding ).
conv_w_decl->read( IMPORTING data = xml_with_declaration ).
" make XML without XML declaration
DATA writer_without_declaration TYPE REF TO if_sxml_writer.
DATA xml_without_declaration TYPE string.
writer_without_declaration = CAST if_sxml_writer( cl_sxml_string_writer=>create( ) ). " <= ** no ** XML declaration
writer_without_declaration->write_node( writer_without_declaration->new_open_element( name = 'test_tag' ) ) .
writer_without_declaration->write_node( writer_without_declaration->new_close_element( ) ).
DATA(conv_wo_decl) = cl_abap_conv_in_ce=>create( input = CAST cl_sxml_string_writer( writer_without_declaration )->get_output( ) encoding = zif_lib_print_serializer=>c_encoding ).
conv_wo_decl->read( IMPORTING data = xml_without_declaration ).
BREAK-POINT.
Request clarification before answering.
Workaround:
CALL TRANSFORMATION id SOURCE XML xml_without_declaration
RESULT XML xml_with_declaration.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Monika,
Development released a solution with SAP BTP ABAP Environment 2502. There are now header options for the sXML Library. These are the options:
You can find more in the documentation: https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/ABENABAP_SXML_LIB_RENDER.html (hint section).
Best regards,
Lena
| User | Count |
|---|---|
| 18 | |
| 7 | |
| 6 | |
| 6 | |
| 6 | |
| 4 | |
| 3 | |
| 3 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.