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

read xml filr from application server

Former Member
0 Likes
4,140

Hi I want to read an XML file from application server. can anyone please give me the sample code?

Please its very urgent,

Thanks

6 REPLIES 6
Read only

Former Member
0 Likes
1,434

<b><REMOVED BY MODERATOR></b>

Message was edited by:

Alvaro Tejada Galindo

Read only

0 Likes
1,434

hey, thanks a lot for ur immediate response.

I too have that code, jus wanted to know what value am I supposed to pass in the last part of the code 'CALL TRANSFORMATION ('ID')'.

what value am i suppsoed to pass in this ID??

Please help me in this

Thanks

Read only

0 Likes
1,434

Hi,

You need to pass XSLT transformation definition you have created.

a®

Read only

0 Likes
1,434

can you please xplain abt it in details. How do i have to create tht?

Am new to this and would like to know in detail.

Read only

0 Likes
1,434

Hi,

Please check this

/people/tobias.trapp/blog/2005/05/04/xml-processing-in-abap-part-1

If you don't have prior XML exposure then use as suggested by Uwe

a®

Read only

uwe_schieferstein
Active Contributor
0 Likes
1,434

Hello

The following sample report <b>ZUS_SDN_BCCIIXMLT2</b> (modified from BCCIIXMLT2) shows how to upload an XML file from the application server.

If the structure of the XML is according to the structure of a DDIC structure then you can directly convert the XML into the DDIC record using the transformation ID (= identical) which is used to convert ABAP to XML and vice versa.

*
*  BCCIIXMLT2 - sample program
*
*  This sample program shows how to read an XML document from a file
*  in the appserver's file system, parse the document into a DOM
*  representation and display the content as a list.
*  Additionally the DOM representation is rendered back into an XML
*  stream and stored as an output XML file on the appserver machine.
*
*  This sample program uses ABAP strings to represent the XML input
*  and output streams. See BCCIIXMLT1 for using internal tables.
*


REPORT zus_sdn_bcciixmlt2 MESSAGE-ID bcciixmlt3_msg LINE-SIZE 1000.


DATA:
  gd_rc     TYPE sysubrc,
  go_doc    TYPE REF TO cl_xml_document.


START-OF-SELECTION.

  PARAMETERS: filename(80) TYPE c
          DEFAULT 'tempIDoc_430040.xml'.  "#EC NOTEXT

*-- read the XML document from a dataset into a string
  DATA: inputstring TYPE xstring.
  OPEN DATASET filename FOR INPUT IN BINARY MODE.
  IF sy-subrc NE 0.
    MESSAGE e000.
  ENDIF.
  READ DATASET filename INTO inputstring.
  CLOSE DATASET filename.



  CREATE OBJECT go_doc.
  CALL METHOD go_doc->parse_xstring
    EXPORTING
      stream  = inputstring
    RECEIVING
      retcode = gd_rc.
  CALL METHOD go_doc->display
*    EXPORTING
*      WITH_BDN = SPACE
      .



*-- create the main factory
  DATA: pixml TYPE REF TO if_ixml.
  pixml = cl_ixml=>create( ).

*-- create the initial document
  DATA: pdocument TYPE REF TO if_ixml_document.
  pdocument = pixml->create_document( ).

*-- create the stream factory
  DATA: pstreamfactory TYPE REF TO if_ixml_stream_factory.
  pstreamfactory = pixml->create_stream_factory( ).

*-- create a stream for the input (string)
  DATA: pistream TYPE REF TO if_ixml_istream.
  pistream = pstreamfactory->create_istream_xstring( inputstring ).


*-- create the parser
  DATA: pparser TYPE REF TO if_ixml_parser.
  pparser = pixml->create_parser( stream_factory  = pstreamfactory
                                    istream       = pistream
                                    document      = pdocument ).

*-- parse the stream
  IF pparser->parse( ) NE 0.
    IF pparser->num_errors( ) NE 0.
      DATA: count TYPE i.
      count = pparser->num_errors( ).
      WRITE: count, ' parse errors have occured:'.          "#EC NOTEXT
      DATA: pparseerror TYPE REF TO if_ixml_parse_error,
            i TYPE i.
      DATA: index TYPE i VALUE 0.
      WHILE index < count.
        pparseerror = pparser->get_error( index = index ).
        i = pparseerror->get_line( ).
        WRITE: 'line: ', i.                                 "#EC NOTEXT
        i = pparseerror->get_column( ).
        WRITE: 'column: ', i.                               "#EC NOTEXT
        DATA: string TYPE string.
        string = pparseerror->get_reason( ).
        WRITE: string.
        index = index + 1.
      ENDWHILE.
    ENDIF.
  ENDIF.

*-- we don't need the stream any more, so let's close it...
  CLEAR pistream.



*-- just for fun: render the DOM back into an output stream/xstring
  DATA: postream TYPE REF TO if_ixml_ostream,
        outputstring TYPE xstring.
  postream = pstreamfactory->create_ostream_xstring( outputstring ).
  CALL METHOD pdocument->render( ostream = postream ).

*-- write the XML document as a dataset
  DATA: dsn(80) TYPE c.
  CONCATENATE filename '.out' INTO dsn.                     "#EC NOTEXT
  OPEN DATASET dsn FOR OUTPUT IN BINARY MODE.
  TRANSFER outputstring TO dsn.
  CLOSE DATASET dsn.


*-- print the whole DOM tree as a list...
  DATA: pnode TYPE REF TO if_ixml_node.
  pnode = pdocument.
  PERFORM print_node USING pnode.





*---------------------------------------------------------------------*
*       FORM print_node                                               *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
FORM print_node USING value(pnode) TYPE REF TO if_ixml_node.
  DATA: indent      TYPE i.
  DATA: ptext       TYPE REF TO if_ixml_text.
  DATA: string      TYPE string.

  indent  = pnode->get_height( ) * 2.

  CASE pnode->get_type( ).
    WHEN if_ixml_node=>co_node_element.
      string  = pnode->get_name( ).
      WRITE: AT /indent '<', string, '> '.                  "#EC NOTEXT
    WHEN if_ixml_node=>co_node_text.
      ptext ?= pnode.
      IF ptext->ws_only( ) IS INITIAL.
        string = pnode->get_value( ).
        WRITE: AT /indent string.
      ENDIF.
  ENDCASE.

  pnode = pnode->get_first_child( ).
  WHILE NOT pnode IS INITIAL.

    PERFORM print_node USING pnode.
    pnode = pnode->get_next( ).

  ENDWHILE.

ENDFORM.                    "print_node

Regards

Uwe