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 not displaying correctly

Former Member
0 Likes
3,796

Hi SAP Experts,

I have generated an XML file through XSLT_TOOL and used that in a program. However, when I opened the file the display is unformatted.

Currently, I fix this by opening the xml file in the notepad. Then save it without changing anything. When I open it again, it's displaying correctly.

I do not understand why this is happening and also why the file generated by the program is unformatted unlike the 2nd screenshot.

Can anyone explain this?

Thank you and Regards,

Esteves Jaleco

7 REPLIES 7
Read only

ziolkowskib
Active Contributor
0 Likes
3,001

Hi,

Are you using CL_GUI_HTML_VIEWER to display XML or something else? If not how do you display the XML document?

BTW. Good luck with JPK implementation

Read only

0 Likes
3,001

Hi Bartosz,

Oh, I'm not aware of this class. I'll try using this. Currently, after i have created my xml table, using CALL TRANSFORMATION z_trans SOURCE jpk = i_jpk RESULT XML l_xml,  i converted l_xml from xstring to binary then binary to table of string. then i downloaded this via cl_gui_frontend_services=>gui_download. then i opened it via the same class and using method =>execute.

Thank you. I'm guessing you had an experience in implementing this?


Regards,

Esteves

Read only

0 Likes
3,001

Indeed, I had

I was displaying 2 XMLs next to each other hence the splitter class but I believe you will find the below sample useful.


DATA lo_html_viewer_req TYPE REF TO CL_GUI_HTML_VIEWER.

DATA lo_splitter TYPE REF TO cl_gui_splitter_container.

DATA lo_container_req TYPE REF TO cl_gui_container.

CALL METHOD lo_splitter->get_container

    EXPORTING

      row      = 1

      column    = 1

    RECEIVING

      container = lo_container_req.

  CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'

    EXPORTING

      buffer        = lv_xml_req

    IMPORTING

      output_length = lv_length

    TABLES

      binary_tab    = lt_data[].

  IF lo_html_viewer_req IS BOUND.

    lo_html_viewer_req->close_document( ).

  ELSE.

    CREATE OBJECT lo_html_viewer_req

      EXPORTING

        parent            = lo_container_req

      EXCEPTIONS

        cntl_error        = 1

        cntl_install_error = 2

        dp_install_error  = 3

        dp_error          = 4

        OTHERS            = 5.

    IF sy-subrc <> 0.

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

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

    ENDIF.

  ENDIF.

  lo_html_viewer_req->load_data(

    EXPORTING

      type                  = 'application'    " Type of a MIME Object

      subtype                = 'xml'    " Subtype of a MIME Object

      size                  = lv_length    " Length of Data

*      encoding              =    " Encoding for MIME Object

*      charset                =    " Encoding for MIME Object

    IMPORTING

      assigned_url          = lv_url    " URL

    CHANGING

      data_table            = lt_data[]    " data table

*      iscontentchanged      =    " Sets to 1 if the content is filtered else it is 0

    EXCEPTIONS

      dp_invalid_parameter  = 1

      dp_error_general      = 2

      cntl_error            = 3

      OTHERS                = 5

  ).

  IF sy-subrc <> 0.

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

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

  ENDIF.

  lo_html_viewer_req->show_url( lv_url ).

Read only

0 Likes
3,001

Hi,

From the code, I saw that you are using gui containers. What if I'm not using any screens? I just want to download the file and be able to display it correctly?

Thank you.

Read only

0 Likes
3,001

So when you download the file, the file itself is corrupted - is that correct?

Have you tried downloading your XML as 'BIN' instead of 'ASC' (parameter FILETYPE of CL_GUI_FRONTEND_SERVICES=>GUI_DOWNLOAD) and skipping the step where you convert binary to string?

BTW. What do you mean that you are not displaying the file? So how did you notice you have problem with displaying the file in SAP? 

Read only

0 Likes
3,001

No, not necessarily corrupted. I am currently using BIN and file is generated properly. however the display is wrong. As you can see from the first snippet, there is no formatting whatsoever. however when i opened the file via the notepad and saved it without changing anything, I am getting the desired xml display.

Read only

0 Likes
3,001

I'm still missing a step here I understand that you have issue with displaying but I do not understand how you display your XML in SAP - could you please explain?

It  could be me or that it's Friday afternoon but I simply did not catch how or where you display the file