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

Create Root Element in XML

Former Member
0 Likes
1,373

Hi Experts,

I am develpoing a program to generate xml file as output. I am using the method CL_IXML and other interfaces to generate the xml data. Here I need to create a root element. I did search in SDN but I couldnot found anything to generate xml root element.

My output should be like this:

<?xml version="1.0" encoding="UTF-8"?>

<Request Version="11.1" IssuerID="1">

<CreatePurchaseRequest

RequestID="123456"

Commonname="test"

........

........

</CreatePurchaseRequest>

</Request>

Can anybody plz suggest how can I generate the root element Request here?

Regards,

Ranganadh.

1 ACCEPTED SOLUTION
Read only

Sandra_Rossi
Active Contributor
0 Likes
1,026

Hi,

The first node created in the document, will be the root node (root element if you prefer).

If you want more information, please paste your code.

Sandra

2 REPLIES 2
Read only

Sandra_Rossi
Active Contributor
0 Likes
1,027

Hi,

The first node created in the document, will be the root node (root element if you prefer).

If you want more information, please paste your code.

Sandra

Read only

0 Likes
1,026

Thanks Sandra,

My issue got resolved.

I just created the root element using the method create_sample_element and set the attributes using set_attributes method.

Thanks for your help.

w_ixml = cl_ixml=>create( ).
      w_document = w_ixml->create_document( ).
      w_root = w_ixml->create_document( ).

      IF w_document IS INITIAL.
        RAISE EXCEPTION TYPE cx_cmx_da_exception
          EXPORTING
            textid = cx_cmx_da_exception=>cx_cmx_da_error_internal.
      ENDIF.

      w_encoding = w_ixml->create_encoding(
                             character_set = 'utf-8'
                             byte_order    = if_ixml_encoding=>co_none ).
      w_document->set_encoding( w_encoding ).

      w_element_inv1  = w_document->create_simple_element(
                  name = 'OrbiscomRequest'
                  parent = w_document ).

      w_element_inv1->set_attribute( name = 'Version'
                                     namespace = ''
                                     value = '11.1' ).

      w_element_inv1->set_attribute( name = 'IssuerID'
                                     namespace = ''
                                     value = '1' ).