Skip to Content
0
Nov 10, 2005 at 09:44 AM

XML stream utf-8 encoding

821 Views

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