Application Development 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: 

How to control the formatting of exported XML files? FM: SDIXML_DATA_TO_DOM

Former Member
0 Kudos

How to export XML files like this? Thank you.

<b><?xml version="1.0" encoding="GB2312"?>

<tag1 attribute="blabla">

<tag2>blabla</tag2>

<tag3 attribute="blabla">blabla</tag3>

</tag1></b>

The code below does not work as I expected.

REPORT ZTEST_XML .

data: it_table like t001 occurs 0.

data: l_dom TYPE REF TO IF_IXML_ELEMENT,

m_document TYPE REF TO IF_IXML_DOCUMENT,

g_ixml TYPE REF TO IF_IXML,

w_string TYPE XSTRING,

w_size TYPE I,

w_result TYPE I,

w_line TYPE STRING,

it_xml TYPE DCXMLLINES,

s_xml like line of it_xml,

w_rc like sy-subrc.

start-of-selection.

select * from t001 into table it_table.

end-of-selection.

********************************************

        • initialize iXML-Framework ****

********************************************

write: / 'initialiazing iXML:'.

class cl_ixml definition load.

g_ixml = cl_ixml=>create( ).

check not g_ixml is initial.

write: 'ok'.

********************************************

        • create DOM from SAP data ****

********************************************

write: / 'creating iXML doc:'.

m_document = g_ixml->create_document( ).

check not m_document is initial.

write: 'ok'.

write: / 'converting DATA TO DOM 1:'.

CALL FUNCTION 'SDIXML_DATA_TO_DOM'

EXPORTING

NAME = 'IT_TABLE'

DATAOBJECT = it_table[]

IMPORTING

DATA_AS_DOM = l_dom

CHANGING

DOCUMENT = m_document

EXCEPTIONS

ILLEGAL_NAME = 1

OTHERS = 2.

if sy-subrc = 0. write 'ok'.

else. write: 'Err =', sy-subrc.

endif.

check not l_dom is initial.

write: / 'appending DOM to iXML doc:'.

w_rc = m_document->append_child( new_child = l_dom ).

if w_rc is initial. write 'ok'.

else. write: 'Err =', w_rc.

endif.

********************************************

        • visualize iXML (DOM) ****

********************************************

write: / 'displaying DOM:'.

CALL FUNCTION 'SDIXML_DOM_TO_SCREEN'

EXPORTING

DOCUMENT = m_document

EXCEPTIONS

NO_DOCUMENT = 1

OTHERS = 2.

if sy-subrc = 0. write 'ok'.

else. write: 'Err =', sy-subrc.

endif.

********************************************

        • convert DOM to XML doc (table) ****

********************************************

write: / 'converting DOM TO XML:'.

CALL FUNCTION 'SDIXML_DOM_TO_XML'

EXPORTING

DOCUMENT = m_document

  • PRETTY_PRINT = ' '

IMPORTING

XML_AS_STRING = w_string

SIZE = w_size

TABLES

XML_AS_TABLE = it_xml

EXCEPTIONS

NO_DOCUMENT = 1

OTHERS = 2.

if sy-subrc = 0. write 'ok'.

else. write: 'Err =', sy-subrc.

endif.

write: / 'XML as string of size:', w_size, / w_string.

describe table it_xml lines w_result.

write: / 'XML as table of', w_result, 'lines:'..

loop at it_xml into s_xml.

write s_xml.

endloop.

write: / 'end of processing'.

1 ACCEPTED SOLUTION

guillaume-hrc
Active Contributor
0 Kudos

Hi,

As of WAS 6.20, you can use XSLT programs to produce XML from ABAP variables.

Go in transaction SE80 to create those programs.

You can then call them from BAP using the CALL TRANSFORMATION statement.

More information here:

https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/c5b0d190-0201-0010-11b8-aabe2701...

Best regards,

Guillaume

2 REPLIES 2

Former Member
0 Kudos

Try creating the table with deep structure . That may help you .

guillaume-hrc
Active Contributor
0 Kudos

Hi,

As of WAS 6.20, you can use XSLT programs to produce XML from ABAP variables.

Go in transaction SE80 to create those programs.

You can then call them from BAP using the CALL TRANSFORMATION statement.

More information here:

https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/c5b0d190-0201-0010-11b8-aabe2701...

Best regards,

Guillaume