Skip to Content
author's profile photo
Former Member

Even Based XML Parsing in ABAP

Hi all ,

Currently i am using DOM Based Parsing to parse XML in my ABAP program. i am planning to change the code by using Event based parsing which is recommended for perfomance when we parse large xml document

Any one have the Example program for event based parsing the xml .pls help me in this.

Thanks in Advance

Ram

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

1 Answer

  • author's profile photo
    Former Member
    Aug 03, 2004 at 03:30 PM

    Hello,

    you can look at the coding example

    data: event type ref to if_ixml_event,

    event_sub type i

    lp_dom type ref to if_ixml_document,

    pstreamfac TYPE REF TO if_ixml_stream_factory,

    pistream TYPE REF TO if_ixml_istream,

    .

    • create the factory for streams

    pstreamfac = g_ixml->create_stream_factory( ).

    • create the input stream:

    pistream = pstreamfac->create_istream_cstring( string = xml ).

    lp_dom = g_ixml->create_document( ).

    • create the iXML parser:

    parser = g_ixml->create_parser(

    stream_factory = pstreamfac

    istream = pistream

    document = lp_dom ).

    • let the parser know which events I am interested in

    event_sub = if_ixml_event=>co_event_element_pre2 +

    if_ixml_event=>co_event_element_post.

    parser->set_event_subscription( events = event_sub ).

    do.

    event = parser->parse_event( ).

    if event is initial.

    exit. ' either end reached or error (check below)

    endif.

    data: str type string.

    case event->get_type( ).

    when if_ixml_event~co_event_element_pre2.

    str = event->get_name( ). write: '<' str '>'.

    when if_ixml_event~co_event_text_post.

    str = event->get_value( ). write: str.

    ...

    endcase.

    enddo.

    • always check for errors:

    if parser->num_errors( ) ne 0.

    ...

    endif.

    Regards,

    Marc

    Add comment
    10|10000 characters needed characters exceeded

    • Hi!

      When you are using iXML in an event-based way I suggest to disable implicit generation of the whole DOM-Tree:

      CALL METHOD l_rif_pparser->set_dom_generating

      EXPORTING

      is_generating = space

      RECEIVING

      rval = l_var_rval.

      Hope that helps!

      Tobias