ABAP Keyword Documentation → ABAP - Reference → Data Interfaces and Communication Interfaces → ABAP and XML → Class Libraries for XML → iXML Library → iXML Library, Examples
iXML Library, Token Parsers and Renderers, Table
Parses XML data to an internal table and renders this table.
Other versions:
7.31 | 7.40 | 7.54
Source Code
REPORT demo_ixml_parse_render_tk_tabl.
CLASS ixml_demo DEFINITION.
PUBLIC SECTION.
CLASS-METHODS main.
ENDCLASS.
CLASS ixml_demo IMPLEMENTATION.
METHOD main.
DATA(out) = cl_demo_output=>new(
)->begin_section( 'XML-Data' ).
DATA(xml) =
`<texts>` &&
`<!-- texts -->` &&
`<text1 format="bold">aaa</text1>` &&
`<text2 format="italic">bbb</text2>` &&
`</texts>`.
out->write_xml( xml ).
out->next_section( 'Node Table' ).
DATA(ixml) = cl_ixml=>create( ).
DATA(token_parser) = ixml->create_token_parser(
stream_factory = ixml->create_stream_factory( )
istream = ixml->create_stream_factory(
)->create_istream_string( xml )
document = ixml->create_document( ) ).
DATA(tk_mask) =
if_ixml_token_parser=>co_tk_any_token.
DATA(in_mask) =
if_ixml_token_parser=>co_ni_all_info.
DATA node_info TYPE sixmlnode.
DATA(rc) = token_parser->parse_tokens( token_mask = tk_mask
info_mask = in_mask ).
IF rc <> 0.
"Error handling ...
ENDIF.
DATA(node_infos) = token_parser->tokens.
out->write_data( node_infos ).
out->next_section( 'Modified Node Table' ).
DELETE node_infos WHERE type =
if_ixml_token_parser=>co_tk_attribute.
out->write_data( node_infos ).
out->next_section( 'New XML-Data' ).
CLEAR xml.
DATA(token_renderer) = ixml->create_token_renderer(
ostream = ixml->create_stream_factory(
)->create_ostream_cstring( xml ) ).
token_renderer->render( node_infos ).
out->write_xml( xml ).
out->display( ).
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
ixml_demo=>main( ).
Description
Using a token parser, XML is parsed directly to the attribute TOKENS with the type SIXMLDOM. The nodes for the attributes are then removed. The modified table is passed to a token renderer. The result is the XML data without attributes.
Instead of removing the attributes in the ABAP program, the value of if_ixml_token_parser=>co_tk_attribute
can simply be subtracted from the actual parameter for tk_mask
. The parser then does not place the attributes in the internal table.