‎2005 Sep 06 3:39 PM
Hi all,
When I use a simple transformation (with CALL TRANSFORMATION) to create xml-string from ABAP structure I get an xml-string which starts with <?xml version="1.0" encoding="utf-16"?>.
I wonder if it is possible to get the encoding in UTF-8?
The result of the transformation is saved in a table with string type variable.
Do I have to add something to my transformation source?
Thanks in advance,
Fred.
‎2005 Sep 06 4:06 PM
hi, I use the CALL TRANSFORMATION a little difference with yours, but it can achieve your target.
data: g_ixml type ref to if_ixml.
data: g_stream_factory type ref to IF_IXML_STREAM_FACTORY.
data: resstream type ref to if_ixml_ostream.
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 ).
resstream = g_stream_factory->CREATE_OSTREAM_ITABLE( table = restab ).
call method resstream->set_encoding
exporting encoding = g_encoding.
call transformation XXXX
source itab = XXXX
result xml resstream.
‎2005 Sep 06 3:48 PM
‎2005 Sep 06 3:56 PM
I don't think the sample provided will work in this case. He is setting the HTTP Response to UTF-8, but not generating the XML itself that way.
In order to generate XML thorugh a transforamtion in UTF-8 you have to set the encoding on the output stream factory. I assume you are getting UTF-16 by default because you have a Unicode system.
constants:
* encoding for download of XML files
encoding type string value 'UTF-8'.
data: resstream type ref to if_ixml_ostream,
ressize type i value 0.
****Create an instance of the Ixml Processor
g_ixml = cl_ixml=>create( ).
****Create the Stream Factory
g_stream_factory = g_ixml->create_stream_factory( ).
****Create an Endcoding and Byte Order
g_encoding = g_ixml->create_encoding( character_set = encoding
byte_order = 0 ).
****Create the output stream with a pointer to our binary string
resstream =
g_stream_factory->create_ostream_xstring( r_xstring ).
****Set the Encoding into a stream
resstream->set_encoding( encoding = g_encoding ).
****Call Transformation using the simple XSLT id_indent
call transformation id_indent
source itab = <tab>
result xml resstream.
‎2005 Sep 06 4:06 PM
hi, I use the CALL TRANSFORMATION a little difference with yours, but it can achieve your target.
data: g_ixml type ref to if_ixml.
data: g_stream_factory type ref to IF_IXML_STREAM_FACTORY.
data: resstream type ref to if_ixml_ostream.
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 ).
resstream = g_stream_factory->CREATE_OSTREAM_ITABLE( table = restab ).
call method resstream->set_encoding
exporting encoding = g_encoding.
call transformation XXXX
source itab = XXXX
result xml resstream.
‎2005 Sep 07 10:51 AM
Thanks for the answers,
I now need to write the resstream to an xml-file on an external file server how do I use the resstream in your examples in
(for example) fm 'GUI_DOWNLOAD'.
Thanks in advance.
Fred
‎2005 Sep 07 10:51 AM
Thanks for the answers,
but how do I use the resstream in your examples in for example fm 'GUI_DOWNLOAD' to write the resstream to an xml-file on an external file server
Thanks in advance.
Fred
‎2005 Sep 07 11:02 AM
Choose the format of the RESSTEAM object that you want. You could go to the Binary String and then convert that Binary String to a Internal Table of Bytes (using function module SCMS_XSTRING_TO_BINARY) or perhaps try the CREATE_OSTREAM_ITABLE.
Either way you end up with an internal table of bytes that can be downloaded using the GUI_DOWNLOAD or CL_GUI_FRONTEND_SERVICES.