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

XML encoding issue

Former Member
0 Likes
2,005

Hello Friends,

    I've a requirement where I upload the XML into SAP using GUI_Upload ( Binary Mode , encoding 4110). Then I use FM - SCMS_BINARY_TO_XSTRING to change to XSTRING. Later I do parsing using FM- SMUM_XML_PARSE.  This gives me data into proper internal table. Here I delete few duplicate records and again use FM - SCMS_XSTRING_TO_BINARY to change this into Binary format. Further I use FM GUI_DOWNLOAD to download this into XML format.

Everything goes fine except that I don't see any encoding in first line.

This is how it looks like:

<?xml version="1.0"?>


This is how it is supposed to look:


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


The encoding UTF-8 is missing in my XML file. Please help me if anyone has come across this situation or any suggestions to achieve the above functionality.

4 REPLIES 4
Read only

Former Member
0 Likes
1,109

so when you are finished editing your xml your internal table has got the encoding attribute there?

from my experience, the IF_IXML* classes do not add or remove anything to/from the document.

Read only

0 Likes
1,109

No Jozef...it's not there post editing.

Do you have workaround which can help to achieve it.

Read only

0 Likes
1,109

I'll have to ask the question once again. Is the attribute there when you are finished changing the internal table? If not, that probably means you deleted it somehow.

So:

- is the attribute there after the first conversion to the internal table?

- is it there after the table operations before exporting to xstring?

Read only

Former Member
0 Likes
1,109

Hi Gaurav,

The FM SCMS_XSTRING_TO_BINARY  which you are using does not create a header with the encoding, as required. For this either you need to go for XSLT transformation and use

CALL TRANSFORMATION (ID created in XSLT)

    SOURCE xml xml_file

    RESULT xml_output = int_tab.

I too have such scenario and I used the below approach.

You can insert the encoding in the header before using SCMS_XSTRING_TO_BINARY.

For that use the below sequence of code:

1) Convert the original header into xstring format by using FM SCMS_BINARY_TO_XSTRING as below:

CALL FUNCTION SCMS_BINARY_TO_XSTRING

EXPORTING

     TEXT = LC_HEADER

IMPORTING

     BUFFER = LV_HEADER.

where lc_header is your original header without encoding.

2) Similarly convert the new header text to xstring

3) Now assign lv_header and lv_header_new into string type variables lv_header_old_str and lv_header_new_str where lv_header_str/lv_header_new_str type string and data obtained from FM-SMUM_XML_CREATE_X into g_data_str of string type variable.

4) REPLACE FIRST OCCURRENCE OF LV_HEADER_OLD_STR IN G_DATA_STR WITH LV_HEADER_NEW_STR.

5) Assign g_data_str back to xstring type :

g_data = g_data_str

6) Use FM SCMS_XSTRING_TO_BINARY to create binary format itab:

CALL FUNCTION SCMS_XSTRING_TO_BINARY

EXPORTING

     BUFFER = G_DATA

IMPORTING

     OUTPUT LENGTH = LENGTH

TABLES

     BINARY_TAB = ITAB.

7) And then download using GUI_DOWNLOAD.

Hope this helps

Thanks

Shradha