sXML Library - Object-Oriented Rendering
Just as in token-based rendering, object-oriented rendering creates an XML writer. The nodes are not written, however, using a separate method for each node type, but using a single method, WRITE_NODE. This method is associated with a node object with the required node type using its input parameters and a corresponding node is appended to the current writer position.
7.31 | 7.40 | 7.54
As in token-based rendering, the XML writer is created using the factory method CREATE of the class in question, for example:
DATA(writer) = CAST if_sxml_writer( cl_sxml_string_writer=>create( ... ) ).
Before the node object is written, it can be created using one of the dedicated methods of the interface IF_SXML_READER, such as NEW_OPEN_ELEMENT, NEW_CLOSE_ELEMENT, and NEW_VALUE or it can be taken from another source, such as an object-oriented read, for example:
writer->write_node( open_element ).
DATA(value) = writer->new_value( ).
value->set_value( ... ).
writer->write_node( value ).
DATA(close_element) = writer->new_close_element( ... ).
writer->write_node( close_element ).
The node object of an opened element has methods that can be used to insert XML attributes.
Methods for Object-Oriented Rendering
The following methods of the interface IF_SXML_WRITER are designed specially for object-oriented rendering:
- NEW_OPEN_ELEMENT - Creates a node object for an opened element.
- NEW_VALUE - Creates a node object for a character-like value.
- NEW_VALUE_RAW - Creates a node object for byte-like raw data.
- NEW_CLOSE_ELEMENT - Creates a node object for a closed element.
- WRITE_NODE - Creates a node as specified by the passed node object.
The values are written as in token-based rendering.
- Token-based rendering and object-oriented rendering are not strictly separate from each other. The corresponding methods for writing nodes can be called alternately in the same program. This is not recommended, though, since the program must remain easy to read.
- In object-oriented rendering, node objects can be written directly that were returned (and possibly modified) by an object-oriented parser.
- Object-oriented rendering can demonstrate poorer performance than token-based rendering due to the extra objects that are created.