ABAP variables to XML format
- Create an instance of the simple renderer (optionally passing static mappings for the names of the tags),
which implements ZIF_XML_RENDERER and handles internal tables, structures, and elemental variables1:
final(xml_renderer) = new zcl_simple_xml_renderer( ).
- Call the process method with an XML Writer and a variable as arguments:
final(writer) = cl_sxml_string_writer=>create( ). xml_renderer->process( i_writer = cast #( writer ) i_data = VAR ).
- Use the writer as usual:
final(encoded_xml) = writer->get_output( ).
You can run class ZCL_XML_SIMPLE_RENDERER_EG_APP to see how a short XML file can be generated.
Footnotes
-
You can also implement interface ZIF_XML_RENDERER yourself to create the XML file however you prefer ↩