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: 

Remove tag from XML

Former Member
0 Kudos

Hi,

I'm creating a XML from ABAP, everything works fine but when the XML is created is added one tag <item> that i want to remove. How can i do that?

The code that i'm using is this:

CLASS cl_ixml DEFINITION LOAD.

g_ixml = cl_ixml=>create( ).

CHECK NOT g_ixml IS INITIAL.

m_document = g_ixml->create_document( ).

CHECK NOT m_document IS INITIAL.

WRITE: / 'Converting DATA TO DOM 1:'.

CALL FUNCTION 'SDIXML_DATA_TO_DOM'

EXPORTING

name = 'FICHEIROBALANCETE'

dataobject = ficheirobalancete[]

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.

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

IF w_rc IS INITIAL.

WRITE 'Ok'.

ELSE.

WRITE: 'Err =',

w_rc.

ENDIF.

CALL FUNCTION 'SDIXML_DOM_TO_XML'

EXPORTING

document = m_document

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.

LOOP AT it_xml INTO xml_tab-d.

APPEND xml_tab.

ENDLOOP.

CALL FUNCTION 'WS_DOWNLOAD'

EXPORTING

bin_filesize = w_size

filename = nome_fich

filetype = 'BIN'

TABLES

data_tab = xml_tab

EXCEPTIONS

OTHERS = 10.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

Best regards,

Ricardo

4 REPLIES 4

Former Member
0 Kudos

Hi Ric,

Please have a look into this link it will be useful

[Tag Item | ]

Use FM:-

SDIXML_DATA_TO_DOM

Thanks

Kalyan b

0 Kudos

Thanks for the reply, but i managed to solve the problem.

0 Kudos

Can you explain how do you resolve the problem?

thanks!

abap11
Explorer
0 Kudos

Here is another solution,

Hex value for string <item> is '3C6974656D3E'

and for string </item> is '3C2F6974656D3E'

with trailing new line hex value is '0A'.

Some changes in this loop

LOOP AT it_xml INTO xml_tab-d.
REPLACE ALL OCCURRENCES OF '3C6974656D3E0A' IN xml_tab-d WITH ' '.
REPLACE ALL OCCURRENCES OF '3C2F6974656D3E0A' IN xml_tab-d WITH ' '.
APPEND xml_tab.
ENDLOOP.

Hope this helps,

Thanks

Sitesh Sawant.