Skip to Content
0
Former Member
Jul 05, 2007 at 11:18 PM

XML to ABAP Using XSLT

28 Views

Hello friends,

I am trying a ABAP program (posted on SDN) to convert XML into ABAP (internal table) and not having any luck. Either it is my table/structure declaration or XSLT. Could any of you experts give me a hand with it please?

Thanks in advance..but points on help! 😊

Here is my XML:

And my ABAP program:

REPORT ZTESTXMLREAD.

TYPE-POOLS: abap, ixml.

class cl_ixml definition load.

TYPES: BEGIN OF t_dc40,

docnum(17) TYPE C,

status(2) TYPE C,

END OF t_dc40.

TYPES: BEGIN OF t_emkt,

spras(2) TYPE C,

maktx(35) TYPE C,

END OF t_emkt.

TYPES: BEGIN OF t_emrm,

matnr(12) TYPE C,

ersda(8) TYPE C,

ernam(25) TYPE C,

emktx TYPE t_emkt,

END OF t_emrm.

TYPES: BEGIN OF t_mm,

dc40 TYPE t_dc40,

emrm TYPE t_emrm,

END OF t_mm.

DATA: l_ixml TYPE REF TO if_ixml,

l_streamfactory TYPE REF TO if_ixml_stream_factory,

l_istream TYPE REF TO if_ixml_istream.

DATA: l_filename TYPE string.

DATA: it_airplus TYPE STANDARD TABLE OF t_mm,

wa_airplus TYPE t_mm.

*Errorvariables

DATA: xslt_err TYPE REF TO cx_xslt_exception,

err_string TYPE string.

PARAMETERS: pa_file TYPE char1024 DEFAULT 'c:Test.XML'.

START-OF-SELECTION.

  • Creating the main iXML factory

l_ixml = cl_ixml=>create( ).

  • Creating a stream factory

l_streamfactory = l_ixml->create_stream_factory( ).

  • Creating input stream

l_istream = l_streamfactory->create_istream_uri( 'file://c:Test.xml' ).

  • here we use the CALL TRANSFORMATION method which calls

TRY.

CALL TRANSFORMATION ZTestXSLT

SOURCE xml l_istream

RESULT xml_output = it_airplus

.

  • catch any error, very helpful if the XSLT isn't correct

CATCH cx_xslt_exception INTO xslt_err.

err_string = xslt_err->get_text( ).

WRITE: / 'Transformation error: ', err_string.

EXIT.

ENDTRY.

  • setting a breakpoint to watch the workarea

  • by the internal table "it_airplus"

break-point.

LOOP AT it_airplus INTO wa_airplus.

ENDLOOP.