cancel
Showing results for 
Search instead for 
Did you mean: 

error in cl_sxml_string_writer, sXML Library

monika_hoenicke
Discoverer
0 Kudos
771

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.

Accepted Solutions (0)

Answers (2)

Answers (2)

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

retired_member
Product and Topic Expert
Product and Topic Expert
0 Kudos

Then:

cl_sxml_string_writer=>createencoding 'UTF-8' )

That will give you the XML header.

 

monika_hoenicke
Discoverer
0 Kudos
It is not our point that we cannot set the XML header. Our goal is that the XML file can be displayed in the debugger as a structure without an XML declaration. How can SAP solve this? See the attached picture.
retired_member
Product and Topic Expert
Product and Topic Expert

Ah jetzt ja.

In CL_DEMO_OUTPUT_STREAM=>WRITE_XML we format XML ourselves to achieve this. Maybe Debugger can do the same. I will ask the colleagues.

Using transformation ID adds the <xml>-Tag what would change the debugged content. This is not desirable.

ralf_wenzel_heuristika
Active Participant
0 Kudos
We still have that problem, at 2024-07-31 you wrote, you will discuss it with your colleagues.
retired_member
Product and Topic Expert
Product and Topic Expert
0 Kudos

Due to the discussion here, our development has introduced the following enhancements with releases 9.14/2502, 8.16/2025:

Header Options for sXML Library

Header options for the XML declaration are now available in the sXML Library:

  • CO_OPT_VAL_NO (no XML header), this is the default option.
  • CO_OPT_VAL_WITHOUT_ENCODING (version)
  • CO_OPT_VAL_WITHOUT_ENCODING (version and encoding)

But regarding the debugger problem, I don't have any further information yet. You might report it as a customer incident.