cancel
Showing results for 
Search instead for 
Did you mean: 

XML stream utf-8 encoding

former_member184313
Participant
0 Kudos

Hi folks,

I'm trying to establish a CSTRING XML stream with utf-8 encoding. I've only managed to do this in XSTRING so far.

If i use this coding, i get a binary output.


  DATA: gt_result TYPE TABLE OF string,
         l_result type string.


  constants: encoding type string value 'UTF-8'.

  data:  g_ixml type ref to if_ixml.
  data:  g_stream_factory type ref to IF_IXML_STREAM_FACTORY.
  data:  g_encoding type ref to if_ixml_encoding.

  g_ixml = cl_ixml=>create( ).
  g_stream_factory = g_ixml->CREATE_STREAM_FACTORY( ).
  g_encoding = g_ixml->create_encoding( character_set = 'utf-8'
                                        byte_order = 0 ).

  data:  resstream type ref to if_ixml_ostream.

  resstream = g_stream_factory->create_ostream_cstring( l_result ).

  call method resstream->set_encoding
    EXPORTING
      encoding = g_encoding.

* XML Transformieren
  CALL TRANSFORMATION id_indent
    SOURCE     itab = it_Itab
    RESULT XML resstream.

* Temporär, XML File erzeugen
  refresh gt_result.
  APPEND l_result TO gt_result.
  CALL METHOD cl_gui_frontend_services=>gui_download
    EXPORTING
      filename         = 'c:test.xml'
    CHANGING
      data_tab         = gt_result
    EXCEPTIONS
      file_write_error = 1.

Without this expression :

g_encoding = g_ixml->create_encoding(
             character_set = 'utf-8' byte_order = 0 ).

I get a cstring stream, but in utf-16.

My question now is, how do I manage to get a utf-8 encoded stream in cstring?

Thanks for your help.

Cheers

Daniel

Accepted Solutions (1)

Accepted Solutions (1)

christian_wohlfahrt
Active Contributor
0 Kudos

Hi Daniel!

g_encoding = g_ixml->create_encoding(

character_set = <b>'UTF-8'</b> byte_order = 0 ).

Try capital letters!

Regards,

Christian

former_member184313
Participant
0 Kudos

Hi Chrisian

Thanks for your reply.

I tryed capitals, no change...

Anyway, good idea.

Cheers

Daniel

former_member184313
Participant
0 Kudos

This is the solution:


METHOD TRANSFORM_XML.
  TYPE-POOLS TRUXS.
*********************** XML ***********************************
  DATA: GT_RESULT TYPE TABLE OF STRING,
         L_RESULT TYPE ETXML_LINE_STR.


  CONSTANTS:  ENCODING     TYPE STRING VALUE 'UTF-8'.

  DATA:  G_IXML TYPE REF TO IF_IXML.
  DATA:  G_STREAM_FACTORY TYPE REF TO IF_IXML_STREAM_FACTORY.
  DATA:  G_ENCODING TYPE REF TO IF_IXML_ENCODING.

  G_IXML = CL_IXML=>CREATE( ).
  G_STREAM_FACTORY = G_IXML->CREATE_STREAM_FACTORY( ).
  G_ENCODING = G_IXML->CREATE_ENCODING( CHARACTER_SET = ENCODING
                                        BYTE_ORDER = 0 ).

  DATA:  RESSTREAM TYPE REF TO IF_IXML_OSTREAM.

  RESSTREAM = G_STREAM_FACTORY->CREATE_OSTREAM_XSTRING( L_RESULT ).

  CALL METHOD RESSTREAM->SET_ENCODING
    EXPORTING
      ENCODING = G_ENCODING.

* XML Transformieren
  CALL TRANSFORMATION ID_INDENT
    SOURCE     ITAB = IT_ITAB
    RESULT XML RESSTREAM.

* XString to String
  CALL FUNCTION 'ECATT_CONV_XSTRING_TO_STRING'
    EXPORTING
      IM_XSTRING  = L_RESULT
      IM_ENCODING = 'UTF-8'
    IMPORTING
      EX_STRING   = E_XML.

* Temporär, XML File erzeugen
  refresh gt_result.
  APPEND e_xml TO gt_result.
  CALL METHOD cl_gui_frontend_services=>gui_download
    EXPORTING
      filename         = 'c:test.xml'
    CHANGING
      data_tab         = gt_result
    EXCEPTIONS
      file_write_error = 1.

ENDMETHOD.

How can I give the 10 points to myself?

Cheers

Daniel

Answers (0)