2013 Jan 30 2:57 PM
Hello,
I use "if_ixml" object to build an XML String.
This is my code :
DATA: lo_ixml TYPE REF TO if_ixml.
DATA: lo_document TYPE REF TO if_ixml_document.
DATA: lo_mt_response TYPE REF TO if_ixml_element.
DATA: lo_streamfactory TYPE REF TO if_ixml_stream_factory.
DATA: lo_ostream TYPE REF TO if_ixml_ostream.
DATA: lo_renderer TYPE REF TO if_ixml_renderer.
DATA: lo_encoding TYPE REF TO if_ixml_encoding.
CONSTANTS: c_encoding TYPE string VALUE 'UTF-8'.
lo_ixml = cl_ixml=>create( ).
lo_document = lo_ixml->create_document( ).
lo_encoding = lo_ixml->create_encoding( character_set = c_encoding
byte_order = 0 ).
lo_document->set_encoding( encoding = lo_encoding ).
lo_mt_response = lo_document->create_simple_element(
name = 'MT_Agreement_Response'
parent = lo_document ).
lo_streamfactory = lo_ixml->create_stream_factory( ).
lo_ostream = lo_streamfactory->create_ostream_cstring( string = response ).
lo_renderer = lo_ixml->create_renderer( ostream = lo_ostream
document = lo_document ).
lo_ostream->set_pretty_print( 'X' ).
lo_renderer->render( ).
When i read my XML String (response) i have a bug with first char.
<?xml version="1.0" encoding="utf-16"?>
<MT_Agreement_Response/>
And the encoding is not "UTF-8"
If you have an idea ... ?
I read the XML Response in .Net (Web Service)
But in my Abap Debugger this problem is already present, not a .Net problem.
Thank you in advance.
Youri
2013 Jan 30 8:31 PM
Youri, your code doesn't show the source where the string (or xstring?) "response" was created. The point is that "response" contains at the beginning the byte order mark EFBBBF for UTF-8 ( http://en.wikipedia.org/wiki/Byte_Order_Mark ), a kind of magical number used by some software to indicate the encoding.
Regards, Rüdiger
Hello,
I use "if_ixml" object to build an XML String.
This is my code :
DATA: lo_ixml TYPE REF TO if_ixml.
DATA: lo_document TYPE REF TO if_ixml_document.
DATA: lo_mt_response TYPE REF TO if_ixml_element.
DATA: lo_streamfactory TYPE REF TO if_ixml_stream_factory.
DATA: lo_ostream TYPE REF TO if_ixml_ostream.
DATA: lo_renderer TYPE REF TO if_ixml_renderer.
DATA: lo_encoding TYPE REF TO if_ixml_encoding.
CONSTANTS: c_encoding TYPE string VALUE 'UTF-8'.
lo_ixml = cl_ixml=>create( ).
lo_document = lo_ixml->create_document( ).
lo_encoding = lo_ixml->create_encoding( character_set = c_encoding
byte_order = 0 ).
lo_document->set_encoding( encoding = lo_encoding ).
lo_mt_response = lo_document->create_simple_element(
name = 'MT_Agreement_Response'
parent = lo_document ).
lo_streamfactory = lo_ixml->create_stream_factory( ).
lo_ostream = lo_streamfactory->create_ostream_cstring( string = response ).
lo_renderer = lo_ixml->create_renderer( ostream = lo_ostream
document = lo_document ).
lo_ostream->set_pretty_print( 'X' ).
lo_renderer->render( ).
When i read my XML String (response) i have a bug with first char.
<?xml version="1.0" encoding="utf-16"?>
<MT_Agreement_Response/>
And the encoding is not "UTF-8"
If you have an idea ... ?
I read the XML Response in .Net (Web Service)
But in my Abap Debugger this problem is already present, not a .Net problem.
Thank you in advance.
Youri
2013 Jan 30 8:31 PM
Youri, your code doesn't show the source where the string (or xstring?) "response" was created. The point is that "response" contains at the beginning the byte order mark EFBBBF for UTF-8 ( http://en.wikipedia.org/wiki/Byte_Order_Mark ), a kind of magical number used by some software to indicate the encoding.
Regards, Rüdiger
2013 Jan 30 9:45 PM
OK, I checked it on my system. "response" has to be of type string, and the content is generated by your code.
However, the string does not contain the strange chars. When I run your code on my system and inspect the string in the debugger, there is no UTF-8 BOM in it (and this would be really mysterious for a STRING anyway).
So the BOM must be added later on in your processing. Maybe, somewhere the string will be converted into an XSTRING? What happens later to "response"? How will it be placed into the HTTP response body? With if_http_response->SET_CDATA()? Or do you convert it into some encoding and call if_http_response->SET_DATA( )?
Regards,
Rüdiger
2013 Jan 30 9:59 PM
The var response is a String.
Have you try to edit the response in debugger ?
Try to delete first Char "<"
The first Char is invisible in my debugger.
But when i try to delete "<", i delete this first char invisible.
After i send the response (string) to a web service.
Nothing special.
Have you an idea for UTF-8 encoding ?
2013 Jan 30 10:06 PM
Thanks for this link.
I just saw :
This table illustrates how BOMs are represented as byte sequences and how they might appear in a text editor that is interpreting each byte as a legacy encoding
UTF-8 = 
This is what I have in my variable response when i display it in an editor.
Will i have to delete ?
2013 Jan 30 10:08 PM
Youri, there is nothing special with the string that I get from your test code. Here is how it looks in the debugger on my system, see the picture below. When I delete the '<' ? Well, then the '?' will be the first character. Nothing special. Nothing strange. A sequence of characters, that's it.
>"After I send the response to a web service".
This seems to be the critical point. At this point, probably the BOM will be plugged in.
Kind regards,
Rüdiger
2013 Jan 30 10:14 PM
Youri,
OK, you got it. These are the three bytes that some programs use to mark a text as UTF-8 encoded. AFAIK, in ABAP conversions you can control whether you want to generate an XSTRING with BOM or without it. (Chosing "Without it" would be better in my eyes: These BOM's are not really a good idea.)
> Will i have to delete ?
It's always better to find out at which place the BOM is inserted, instead of first producing unwanted things, and later deleting them.
Somewhere on the further way, your string will be converted into an xstring, and it is at this place where the UTF-8 BOM gets mixed in. Find this place and surpress the BOM generation.
Regards,
Rüdiger
2013 Jan 30 10:17 PM
Ok this is strange.
In my debugger i have an invisible char ... just after : lo_renderer->render( ).
You think i can delete it ?
And how to have encoding="utf-8" in the first xml tag ?
<?xml version="1.0" encoding="utf-16"?>
Anyway thank you for your help.
2013 Jan 30 10:30 PM
Youri, I find this not so strange as you. My SAP system is an old non-unicode system, using iso-8859-1 as encoding, which is a one-character-one-byte encoding. Your system is a unicode system: This always uses internally UTF-16 (LE) as encoding (which has 1 char = 2 bytes). Probably the first byte that you see is the '00', the MSB from the '<' character.
You better not change manually UTF-16 to UTF-8 in the string - you seem to be tended to! This would be a lie. You would claim a string to be UTF-8 which actually is not UTF-8 but UTF-16.
One way to convert an XML document into an UTF-8 xstring is the identity transformation:
data: lv_response type string,
lv_xresponse type xstring.
perform do changing lv_response.
call transformation id source xml lv_response
result xml lv_xresponse.
break-point.
(Here, the subroutine do contains the code that you posted). If you inspect lv_xresponse in the debugger, it will be UTF-8 encoded. Including the correct encoding attribute in the <?xml?> preamble.
Regards,
Rüdiger
2013 Jan 30 10:32 PM
But even more elegant would be to create an XSTRING ostream instead of a CSTRING ostream as you do. Then, the XML will be created from the beginning as an XSTRING in the UTF-8 format, and there is no need to post-process it at all.
2013 Jan 30 9:34 PM
Hi,
You can use FM SCP_REPLACE_STRANGE_CHARS and remove the strange characters from the string.
Thanks,
Sreekanth
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |