Skip to content

ABAP Keyword Documentation →  ABAP − Reference →  Data Interfaces and Communication Interfaces →  ABAP and XML →  Class Libraries for XML →  sXML Library 

sXML Library - Rendering

To create XML data using sXML Library, the content is passed to a XML writer. A writer of the type is "validating", which means that invalid actions, such as attempts to add an attribute to a value node, raise an exception. An XML writer creates the XML data as a hierarchical tree-like structure where each token is represented by a node assigned uniquely to a subnode (see W3C Information Set). An XML writer can be used to write the data in precisely the same way is read by an XML reader.

The classes and interfaces in sXML Library available for rendering XML data are organized so that there are separate XML writer classes for different requirements. These classes inherit from the abstract superclass CL_SXML_WRITER. The abstract superclass contains implementations of functions required by all writers and includes the interface IF_SXML_WRITER, which contains the components shared by all writers. This interface enables all writers to be accessed in the same way. If special components need to be accessed that are not declared in the interface, a down cast must be used on the class in question.

The specialized writer classes are:

Writers in this class render XML data to a byte string.
Writers in this class render XML data to an internal table with a flat byte-like row type.
Writers in this class render XML data to a file on the host computer of the current AS Instance.
Writers in this class render XML data to an ICF HTTP client.
Writers of this class render the data to XOP format.

Each of these classes has a specific factory method, CREATE, for creating appropriate writers. As well as an XOP writer, the required format and the required character format of the data can be passed to each writer. The standard is XML 1.0 format in the UTF-8 character format. The XOP writer supports the XOP format only. Instructions on standardization and handling empty elements can be passed to the factory method if permitted by the format.

The methods of the interface IF_SXML_WRITER enable serial rendering of XML data. There are two basic ways to do this:

A writer cannot be used more than once for the same XML data or for other data. The writing position of a writer is updated while rendering using its methods. The actions permitted by a writer are specified by its current writing position. For writers that do not write to external repositories, the written XML can be read using the method GET_OUTPUT.

Other versions: 7.31 | 7.40 | 7.54


  • In a suitable writer position, an XML writer from the sXML Library can be used as an XML target of the statement CALL TRANSFORMATION. The output of the transformation is inserted into the output of the writer and its writing position moved accordingly.

  • The writers in the sXML Library do not currently support XML comments, CDATA sections, or processor instructions.

  • If rendering produces content of elements or attributes, the characters <, >, &, ", and ' are transformed automatically into the associated XML notation.

Executable Example

Transformation to XML Writers


sXML Library - Token-Based Rendering

sXML Library - Object-Oriented Rendering