cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

error in cl_sxml_string_writer, sXML Library

monika_hoenicke
Discoverer
0 Kudos
1,335

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_writercl_sxml_string_writer=>createencoding CONV #'UTF-8' ) ) ).    " <= XML declaration
  writer_with_declaration->write_node(  writer_with_declaration->new_open_elementname 'test_tag' ) ) .
  writer_with_declaration->write_nodewriter_with_declaration->new_close_element( ) ).
  DATA(conv_w_decl) = cl_abap_conv_in_ce=>createinput CAST cl_sxml_string_writerwriter_with_declaration )->get_output(  ) encoding zif_lib_print_serializer=>c_encoding ).
  conv_w_decl->readIMPORTING 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_writercl_sxml_string_writer=>create( ) ).    " <= ** no ** XML declaration
  writer_without_declaration->write_node(  writer_without_declaration->new_open_elementname 'test_tag' ) ) .
  writer_without_declaration->write_nodewriter_without_declaration->new_close_element( ) ).
  DATA(conv_wo_decl) = cl_abap_conv_in_ce=>createinput CAST cl_sxml_string_writerwriter_without_declaration )->get_output(  ) encoding zif_lib_print_serializer=>c_encoding ).
  conv_wo_decl->readIMPORTING data xml_without_declaration ).

  BREAK-POINT.

View Entire Topic
retired_member
Product and Topic Expert
Product and Topic Expert

Workaround:

CALL TRANSFORMATION id SOURCE XML xml_without_declaration
                       RESULT XML xml_with_declaration.

monika_hoenicke
Discoverer
0 Kudos
Thank you for your answer. Yes, this is an workaround, but we are interested in getting an solution. The debugger cannot display XML that does not contain a declaration, even though the declaration is optional. Is it better to open a call to solve the program error?
lenapadeken
Product and Topic Expert
Product and Topic Expert
0 Kudos

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:

  • CO_OPT_VAL_NO (no XML header; default)
  • CO_OPT_VAL_WITHOUT_ENCODING (version)
  • CO_OPT_VAL_WITHOUT_ENCODING (version and encoding)

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