Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

dom-structure to columns/rows

Former Member
0 Likes
698

Hi!

I have parsed a xml-file into a dom-structure, but i need to display the (internal) table in columns and rows. I tried to do this with cl_xml_document class, but as i am only a beginner in ABAP i am not able to understand how i should do so...

I post the code below for better understanding...

I know that this should be done with call transformation, but i am learning on the MiniWAS 7.10, and there seems to be a bug, because even sample transaction from the documentation do not work...

I tried to work around that but now i am stuck.

Thx a lot!

REPORT Z_XML_TO_ITAB.

TYPE-POOLS: ixml.

TYPES: t_xml_line(1024) TYPE x.

DATA: l_xml_table TYPE TABLE OF t_xml_line,

l_xml_line TYPE t_xml_line,

l_xml_table_size TYPE i,

l_ixml TYPE REF TO if_ixml.

DATA: l_streamfactory TYPE REF TO if_ixml_stream_factory,

l_istream TYPE REF TO if_ixml_istream.

DATA: l_document TYPE REF TO if_ixml_document,

l_parser TYPE REF TO if_ixml_parser.

DATA: l_parse_error TYPE REF TO if_ixml_parse_error.

CALL METHOD cl_gui_frontend_services=>gui_upload

EXPORTING

filename = 'C:\test.xml'

filetype = 'BIN'

IMPORTING

filelength = l_xml_table_size

CHANGING

data_tab = l_xml_table

EXCEPTIONS

OTHERS = 1.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

*iXML factory

l_ixml = cl_ixml=>create( ).

*Create iXML stream factory and input stream

l_streamfactory = l_ixml->create_stream_factory( ).

l_istream = l_streamfactory->create_istream_itable(

table = l_xml_table

size = l_xml_table_size ).

*Create document and parser

l_document = l_ixml->create_document( ).

l_parser = l_ixml->create_parser(

stream_factory = l_streamfactory

istream = l_istream

document = l_document ).

*Parse the XML

IF l_parser->parse( ) NE 0.

IF l_parser->num_errors( ) NE 0.

...

l_parse_error = l_parser->get_error( index = sy-index ).

...

ENDIF.

ENDIF.

IF l_parser->is_dom_generating( ) EQ 'X'.

PERFORM process_dom USING l_document.

ENDIF.

FORM process_dom USING document TYPE REF TO if_ixml_document.

DATA: node TYPE REF TO if_ixml_node,

iterator TYPE REF TO if_ixml_node_iterator,

nodemap TYPE REF TO if_ixml_named_node_map,

attr TYPE REF TO if_ixml_node,

name TYPE string,

prefix TYPE string,

value TYPE string,

indent TYPE i,

count TYPE i,

index TYPE i.

node ?= document.

CHECK NOT node IS INITIAL.

ULINE.

WRITE: /.

WRITE: /' DOM-TREE'.

WRITE: /.

IF node IS INITIAL. EXIT. ENDIF.

  • create a node iterator

iterator = node->create_iterator( ).

  • get current node

node = iterator->get_next( ).

  • loop over all nodes

WHILE NOT node IS INITIAL.

indent = node->get_height( ) * 2.

indent = indent + 20.

CASE node->get_type( ).

WHEN if_ixml_node=>co_node_element.

  • element node

name = node->get_name( ).

nodemap = node->get_attributes( ).

WRITE: / 'ELEMENT :'.

WRITE: AT indent name COLOR COL_POSITIVE INVERSE.

IF NOT nodemap IS INITIAL.

  • attributes

count = nodemap->get_length( ).

DO count TIMES.

index = sy-index - 1.

attr = nodemap->get_item( index ).

name = attr->get_name( ).

prefix = attr->get_namespace_prefix( ).

value = attr->get_value( ).

WRITE: / 'ATTRIBUTE:'.

WRITE: AT indent name COLOR COL_HEADING INVERSE, '=',

value COLOR COL_TOTAL INVERSE.

ENDDO.

ENDIF.

WHEN if_ixml_node=>co_node_text OR

if_ixml_node=>co_node_cdata_section.

  • text node

value = node->get_value( ).

WRITE: / 'VALUE :'.

WRITE: AT indent value COLOR COL_GROUP INVERSE.

ENDCASE.

  • advance to next node

node = iterator->get_next( ).

ENDWHILE.

ENDFORM. "process_dom

Hi!

I have parsed a xml-file into a dom-structure, but i need to display the (internal) table in columns and rows. I tried to do this with cl_xml_document class, but as i am only a beginner in ABAP i am not able to understand how i should do so...

I post the code below for better understanding...

I know that this should be done with call transformation, but i am learning on the MiniWAS 7.10, and there seems to be a bug, because even sample transaction from the documentation do not work...

I tried to work around that but now i am stuck.

Thx a lot!

REPORT Z_XML_TO_ITAB.

TYPE-POOLS: ixml.

TYPES: t_xml_line(1024) TYPE x.

DATA: l_xml_table TYPE TABLE OF t_xml_line,

l_xml_line TYPE t_xml_line,

l_xml_table_size TYPE i,

l_ixml TYPE REF TO if_ixml.

DATA: l_streamfactory TYPE REF TO if_ixml_stream_factory,

l_istream TYPE REF TO if_ixml_istream.

DATA: l_document TYPE REF TO if_ixml_document,

l_parser TYPE REF TO if_ixml_parser.

DATA: l_parse_error TYPE REF TO if_ixml_parse_error.

CALL METHOD cl_gui_frontend_services=>gui_upload

EXPORTING

filename = 'C:\test.xml'

filetype = 'BIN'

IMPORTING

filelength = l_xml_table_size

CHANGING

data_tab = l_xml_table

EXCEPTIONS

OTHERS = 1.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

*iXML factory

l_ixml = cl_ixml=>create( ).

*Create iXML stream factory and input stream

l_streamfactory = l_ixml->create_stream_factory( ).

l_istream = l_streamfactory->create_istream_itable(

table = l_xml_table

size = l_xml_table_size ).

*Create document and parser

l_document = l_ixml->create_document( ).

l_parser = l_ixml->create_parser(

stream_factory = l_streamfactory

istream = l_istream

document = l_document ).

*Parse the XML

IF l_parser->parse( ) NE 0.

IF l_parser->num_errors( ) NE 0.

...

l_parse_error = l_parser->get_error( index = sy-index ).

...

ENDIF.

ENDIF.

IF l_parser->is_dom_generating( ) EQ 'X'.

PERFORM process_dom USING l_document.

ENDIF.

FORM process_dom USING document TYPE REF TO if_ixml_document.

DATA: node TYPE REF TO if_ixml_node,

iterator TYPE REF TO if_ixml_node_iterator,

nodemap TYPE REF TO if_ixml_named_node_map,

attr TYPE REF TO if_ixml_node,

name TYPE string,

prefix TYPE string,

value TYPE string,

indent TYPE i,

count TYPE i,

index TYPE i.

node ?= document.

CHECK NOT node IS INITIAL.

ULINE.

WRITE: /.

WRITE: /' DOM-TREE'.

WRITE: /.

IF node IS INITIAL. EXIT. ENDIF.

  • create a node iterator

iterator = node->create_iterator( ).

  • get current node

node = iterator->get_next( ).

  • loop over all nodes

WHILE NOT node IS INITIAL.

indent = node->get_height( ) * 2.

indent = indent + 20.

CASE node->get_type( ).

WHEN if_ixml_node=>co_node_element.

  • element node

name = node->get_name( ).

nodemap = node->get_attributes( ).

WRITE: / 'ELEMENT :'.

WRITE: AT indent name COLOR COL_POSITIVE INVERSE.

IF NOT nodemap IS INITIAL.

  • attributes

count = nodemap->get_length( ).

DO count TIMES.

index = sy-index - 1.

attr = nodemap->get_item( index ).

name = attr->get_name( ).

prefix = attr->get_namespace_prefix( ).

value = attr->get_value( ).

WRITE: / 'ATTRIBUTE:'.

WRITE: AT indent name COLOR COL_HEADING INVERSE, '=',

value COLOR COL_TOTAL INVERSE.

ENDDO.

ENDIF.

WHEN if_ixml_node=>co_node_text OR

if_ixml_node=>co_node_cdata_section.

  • text node

value = node->get_value( ).

WRITE: / 'VALUE :'.

WRITE: AT indent value COLOR COL_GROUP INVERSE.

ENDCASE.

  • advance to next node

node = iterator->get_next( ).

ENDWHILE.

ENDFORM. "process_dom

1 REPLY 1
Read only

Former Member
0 Likes
619

Used CALL FUNCTION 'SDIXML_DOM_TO_DATA'