Quantcast
Channel: SCN: Message List - ABAP XML Parsing - get all attributes and values from specific node
Viewing all articles
Browse latest Browse all 10

Re: ABAP XML Parsing - get all attributes and values from specific node

$
0
0

Ok...heres the code!

 

form create_xmldatastream .  data: pixml           type ref to if_ixml,        pdocument       type ref to if_ixml_document,        pstreamfactory  type ref to if_ixml_stream_factory,        pistream        type ref to if_ixml_istream,        pparser         type ref to if_ixml_parser,        event           type ref to if_ixml_event,        type            type i,        indent          type i,        name            type string,        value           type string,        ptext           type ref to if_ixml_text.

*-- create the main factory
  pixml = cl_ixml=>create( ).

*-- create the initial document
  pdocument = pixml->create_document( ).

*-- create the stream factory
  pstreamfactory = pixml->create_stream_factory( ).

*-- create an input stream for the table
  pistream = pstreamfactory->create_istream_string( string =
g_filecontent ).

*-- create the parser
  pparser = pixml->create_parser( stream_factory = pstreamfactory                                  istream        = pistream                                  document       = pdocument ).  data: events type i.  add if_ixml_event=>co_event_element_pre    to events.  add if_ixml_event=>co_event_attribute_post to events.  add if_ixml_event=>co_event_text_post      to events.  pparser->set_event_subscription( events = events ).

* Event based parsing
  do.
* read next event    event = pparser->parse_event( ).    if event is initial.      exit.    endif.
* get event type    type   = event->get_type( ).    pnode   = event->get_node( ).    indent = pnode->get_height( ) * 2.    indent = indent + 20.
* evaluate event type    case type.      when if_ixml_event=>co_event_element_pre.
*     element event        name    = pnode->get_name( ).        value  = pnode->get_value( ).
*        IF name IS NOT INITIAL AND value IS NOT INITIAL.        gs_xmltags-tagname = name.        gs_xmltags-tagvalue = value.        clear name.        clear value.        collect gs_xmltags into gt_xmltags.
*        ENDIF.      when if_ixml_event=>co_event_attribute_post.
*     attr event        name   = pnode->get_name( ).        value  = pnode->get_value( ).
*        IF name IS NOT INITIAL AND value IS NOT INITIAL.        gs_xmltags-tagname = name.        gs_xmltags-tagvalue = value.        clear name.        clear value.        collect gs_xmltags into gt_xmltags.
*        ENDIF.      when if_ixml_event=>co_event_text_post.        name   = pnode->get_name( ).        value  = pnode->get_value( ).
*        IF name IS NOT INITIAL AND value IS NOT INITIAL.        gs_xmltags-tagname = name.        gs_xmltags-tagvalue = value.        clear name.        clear value.        collect gs_xmltags into gt_xmltags.
*        ENDIF.      when others.        name   = pnode->get_name( ).        value  = pnode->get_value( ).
*        IF name IS NOT INITIAL AND value IS NOT INITIAL.        gs_xmltags-tagname = name.        gs_xmltags-tagvalue = value.        clear name.        clear value.        collect gs_xmltags into gt_xmltags.
*        ENDIF.    endcase.  enddo.

endform.                    " create_xmldatastream

 

With this code i get all the values in the xmlfile.

 

Could someone give me a hint on how to read a specific note?

 

I tried:

 

data: attribute type ref to if_ixml_attribute.

attribute = element->get_attribute_node( name = 'status' ).

 

But how do i reach the attributes etc?


Viewing all articles
Browse latest Browse all 10

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>