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

how to create a nested XML

Former Member
0 Likes
1,630

Good Day, i tried using this sample code below but there were no XML file generated.

I hope you can help with this, if there is something missing in source code or we need to activate something in the Admin side for this to work. Thank you in Advance.

*&---------------------------------------------------------------------*
*& Report  YV_IXML_WRITE
*&---------------------------------------------------------------------*

REPORT  YV_IXML_WRITE.

PARAMETERS:

  " Appserver Windows file. Not from Desktop (presentation server)
  p_fname TYPE string DEFAULT 'I:\USR\SAP\PUT\FILE.XML'. 

  " Appserver UNIX file
  " p_fname TYPE string DEFAULT '/usr/SAP/PUT/FILE.XML'.  

DATA: lo_ixml TYPE REF TO if_ixml.

* Create iXML object
lo_ixml = cl_ixml=>create( ).
**********************************************************************
***  Build iXML DOM  *************************************************
**********************************************************************
* Sample XML contents.
*  <?xml version="1.0"?>
*  <Company>
*   <CompanyName>SAP</CompanyName>
*   <Employee Type="FT">
*    <EmployeeName>James</EmployeeName>
*    <EmployeeNumber>007</EmployeeNumber>
*   </Employee>
*  </Company>
DATA: lo_document TYPE REF TO if_ixml_document.
DATA: lo_company  TYPE REF TO if_ixml_element.
DATA: lo_employee TYPE REF TO if_ixml_element.

lo_document = lo_ixml->create_document( ).

lo_company  = lo_document->create_simple_element(
                                    name    = 'Company'
                                    parent  = lo_document ).

lo_document->create_simple_element( name    = 'CompanyName'
                                    parent  = lo_company
                                    value   = 'SAP' ).

lo_employee = lo_document->create_simple_element(
                                    name    = 'Employee'
                                    parent  = lo_company ).

lo_employee->set_attribute(           name  = 'Type'
                                      value = 'FT' ).

lo_document->create_simple_element( name    = 'EmployeeName'
                                    parent  = lo_employee
                                    value   = 'James' ).

lo_document->create_simple_element( name    = 'EmployeeNumber'
                                    parent  = lo_employee
                                    value   = '007' ).
**********************************************************************
*** Create Output Stream and Render **********************************
**********************************************************************

DATA:
      lo_streamfactory  TYPE REF TO if_ixml_stream_factory,
      lo_ostream        TYPE REF TO if_ixml_ostream,
      lo_renderer       TYPE REF TO if_ixml_renderer,
      lv_rc             TYPE i,
      lv_xml_size       TYPE i.

* Create Stream Factory
lo_streamfactory = lo_ixml->create_stream_factory( ).

* Crate Output Stream
lo_ostream  = lo_streamfactory->create_ostream_uri( system_id = p_fname ).

* Craete renderer
lo_renderer = lo_ixml->create_renderer( ostream  = lo_ostream
                                        document = lo_document ).
* Set Pretty Print
lo_ostream->set_pretty_print( 'X' ).

* Render
lv_rc = lo_renderer->render( ).

* Get XML file size
lv_xml_size = lo_ostream->get_num_written_raw( ).

* Display Output
WRITE : 'XML File: ', p_fname, lv_xml_size,  'Bytes'.
2 REPLIES 2
Read only

SimoneMilesi
Active Contributor
0 Likes
1,299

Hello!

I guess you used the wiki here https://wiki.scn.sap.com/wiki/display/ABAP/iXML+-+Create+XML+file correct?
Did you check your filename? The example points to an "I:" drive, maybe you do not have it?
Did you check in debug which passage got no result?

Read only

Former Member
0 Likes
1,299

I changed the path to local drive C: and still no output.