SAP ABAP IXML LIB INPUT OUTPUT



Get Example source ABAP code based on a different SAP table
  



ABAP_IXML - Streams and Documents
ITOC

Input Streams and Output Streams
Input streams are used for the input of XML data into the parser and output streams are used to pass XML data from the renderer. A factory is needed to create a stream, which can be created using the iXML factory as follows: DATA(ixml) = cl_ixml=>create( ).
...
DATA(stream_factory) = ixml->create_stream_factory( ).
The static type of the reference variable stream_factory is then the interface IF_IXML_STREAM_FACTORY , which contains factory methods CREATE_ISTREAM_... for input streams and CREATE_OSTREAM_... for output streams.
Different streams can be created for different data sources and data sinks, such as strings, internal tables, or files specified by URI.



Latest notes:

iXML input streams can be specified as an XML source and iXML output streams can be used as an XML target for XSL transformations called using CALL TRANSFORMATION.
If output streams are bound to internal tables with byte-like line types , the last line is not usually filled completely with content from the stream. The length of the actual data in the line can be determined using the return value of the method GET_NUM_WRITTEN_RAW of the output stream modulo the number of table lines.
ABAP_HINT_END



Example ABAP Coding

The XML result of a transformation of an ABAP data object to the asXML format is used to create an iXML input stream. This stream is then transformed back again. CALL TRANSFORMATION id SOURCE text = `Hello XML!`
RESULT XML DATA(xml_string).

DATA(ixml) = cl_ixml=>create( ).
DATA(stream_factory) = ixml->create_stream_factory( ).
DATA(istream) = stream_factory->create_istream_xstring( xml_string ).

DATA result TYPE string.
CALL TRANSFORMATION id SOURCE XML istream
RESULT text = result.
ABAP_EXAMPLE_END

XML Documents
Each XML stored in DOM format in the memory is managed using a separate object. An object of this type can be created as follows: DATA(ixml) = cl_ixml=>create( ).
...
DATA(document) = ixml->create_document( ).
The static type of the reference variable stream_factory is also IF_IXML_DOCUMENT. A document created in this way
is used to address an XML document stored as DOM,
can be bound to the parser to fill it,
can be used to construct new XML data or modify existing data,
can be passed to the renderer to be output.



Latest notes:

iXML documents can be defined as an XML target, iXML documents and their nodes can be specified as an XML source for XSL transformations called using CALL TRANSFORMATION.
ABAP_HINT_END



Example ABAP Coding

A document is created and used as the XML target of an XSL transformation. The filled document is then passed to a renderer to which an output stream for a character string is bound simultaneously and rendered. The character string then contains the character-like representation of the XML data. DATA(ixml) = cl_ixml=>create( ).
DATA(document) = ixml->create_document( ).

CALL TRANSFORMATION id SOURCE text = `Hello XML!`
RESULT XML document.

DATA xml_string TYPE string.
ixml->create_renderer( document = document
ostream = ixml->create_stream_factory(
)->create_ostream_cstring(
string = xml_string )
)->render( ).
ABAP_EXAMPLE_END