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

Encoding XML in ISO-8859-1 from a unicode system

Former Member
0 Likes
2,336

Hello

I want to generate an XML with an encoding ISO-8859-1. I'm on a unicode platform.

I've done the following program :

It works well with the line 'encoding UTF-16.

With the line encoding 'encoding ISO ...', I have special characters in the sting xml_string.

NB : The program works correctly on a non-unicode platform.

Can you help me ?

Thank you

REPORT .

DATA : xml_string TYPE string.

DATA : BEGIN OF l_id,

numero(10),

systeme TYPE gsval,

date TYPE d,

heure TYPE uzeit,

type(7),

nb_nid TYPE i,

END OF l_id.

DATA: ixml TYPE REF TO if_ixml,

streamfactory TYPE REF TO if_ixml_stream_factory,

encoding TYPE REF TO if_ixml_encoding,

ixml_ostream TYPE REF TO if_ixml_ostream.

START-OF-SELECTION.

l_id-date = sy-datum.

l_id-heure = sy-uzeit.

l_id-type = 'BATCH'.

ixml = cl_ixml=>create( ).

streamfactory = ixml->create_stream_factory( ).

ixml_ostream = streamfactory->create_ostream_cstring( xml_string ).

encoding = ixml->create_encoding( character_set = 'ISO-8859-1' byte_order = 0 ).

  • encoding = ixml->create_encoding( character_set = 'UTF-16' byte_order = 0 ).

ixml_ostream->set_encoding( encoding = encoding ).

CALL TRANSFORMATION ztest_xml

SOURCE id = l_id

RESULT XML ixml_ostream.

BREAK-POINT.

Hello

I want to generate an XML with an encoding ISO-8859-1. I'm on a unicode platform.

I've done the following program :

It works well with the line 'encoding UTF-16.

With the line encoding 'encoding ISO ...', I have special characters in the sting xml_string.

NB : The program works correctly on a non-unicode platform.

Can you help me ?

Thank you

REPORT .

DATA : xml_string TYPE string.

DATA : BEGIN OF l_id,

numero(10),

systeme TYPE gsval,

date TYPE d,

heure TYPE uzeit,

type(7),

nb_nid TYPE i,

END OF l_id.

DATA: ixml TYPE REF TO if_ixml,

streamfactory TYPE REF TO if_ixml_stream_factory,

encoding TYPE REF TO if_ixml_encoding,

ixml_ostream TYPE REF TO if_ixml_ostream.

START-OF-SELECTION.

l_id-date = sy-datum.

l_id-heure = sy-uzeit.

l_id-type = 'BATCH'.

ixml = cl_ixml=>create( ).

streamfactory = ixml->create_stream_factory( ).

ixml_ostream = streamfactory->create_ostream_cstring( xml_string ).

encoding = ixml->create_encoding( character_set = 'ISO-8859-1' byte_order = 0 ).

  • encoding = ixml->create_encoding( character_set = 'UTF-16' byte_order = 0 ).

ixml_ostream->set_encoding( encoding = encoding ).

CALL TRANSFORMATION ztest_xml

SOURCE id = l_id

RESULT XML ixml_ostream.

BREAK-POINT.

5 REPLIES 5
Read only

Former Member
0 Likes
1,277

Hello.

If the problem is with special characters, you may try to convert them to html entities.

 
REPLACE ALL OCCURRENCES OF '&' IN xml_string  WITH '&'.

Edited by: Simo Mertsola on Apr 6, 2010 4:24 PM

Read only

Sandra_Rossi
Active Contributor
0 Likes
1,277

> With the line encoding 'encoding ISO ...', I have special characters in the sting xml_string.

By debug could you display xml_string in both text and hexadecimal, and paste it here please. Thx

Read only

0 Likes
1,277

I find the solution.

I have to generat the XML in hexadecimal, and then to convert with the good encoding.

Thank you for you answer

Read only

andreas_bonhfer
Explorer
0 Likes
1,277

Hello Jean-Christophe Segond

I have the same problem. Could you send me how the code for converting to hexadecimal looks like?

Thanks and best regards

Andreas

Read only

0 Likes
1,277

Forum rules say: no mail (we must share the solution)

I didn't understand what was exactly his issue, and what he exactly meant by "then to convert with the good encoding".

His first sentence means that he used the following program (using Xstring instead of string):


REPORT .

DATA : xml_xstring TYPE xstring.


DATA : BEGIN OF l_id,
numero(10),
systeme TYPE gsval,
date TYPE d,
heure TYPE uzeit,
type(7),
nb_nid TYPE i,
END OF l_id.

DATA: ixml TYPE REF TO if_ixml,
streamfactory TYPE REF TO if_ixml_stream_factory,
encoding TYPE REF TO if_ixml_encoding,
ixml_ostream TYPE REF TO if_ixml_ostream.

START-OF-SELECTION.

l_id-date = sy-datum.
l_id-heure = sy-uzeit.
l_id-type = 'BATCH'.

ixml = cl_ixml=>create( ).
streamfactory = ixml->create_stream_factory( ).
ixml_ostream = streamfactory->create_ostream_xstring( xml_xstring ).

encoding = ixml->create_encoding( character_set = 'ISO-8859-1' byte_order = 0 ).

ixml_ostream->set_encoding( encoding = encoding ).


CALL TRANSFORMATION id
SOURCE id = l_id
RESULT XML ixml_ostream.

* in debug here, you'll see that xml_xstring contains 
* XML result in ISO-8859-1 encoding
BREAK-POINT.