06-29-2007 9:31 AM
Hi experts!
I have to read a german catalogue as xml into an internal table. I have to make some minor changes to the file(write and translate tags , so I converted it into a string (str_gaeb), then I parse it to xml. The string still contains all umlaut characters, but my internal table (itab_upload) not...
I post the code sample below for better understanding...
Can somebody advise me how I can keep the special characters?
Thanks
Johann
POINTS WILL BE REWARDED FOR <u>USEFUL </u>ANSWERS!!!
DATA: o_xml TYPE REF TO cl_xml_document.
DATA: itab_upload TYPE TABLE OF zstr_gaeb WITH HEADER LINE,
str_gaeb TYPE string.
DATA: l_streamfactory TYPE REF TO if_ixml_stream_factory,
l_istream TYPE REF TO if_ixml_istream,
l_dom TYPE REF TO if_ixml_element.
DATA: l_document TYPE REF TO if_ixml_document,
l_parser TYPE REF TO if_ixml_parser,
l_ixml TYPE REF TO if_ixml.
DATA: l_parse_error TYPE REF TO if_ixml_parse_error.
&----
*& CREATING XML-FILE
*&
&----
Create XML Object
CREATE OBJECT o_xml.
CALL METHOD o_xml->parse_string( str_gaeb )
EXPORTING
stream = O_xml
receiving
retcode =
.
*iXML factory
l_ixml = cl_ixml=>create( ).
*Create iXML stream factory and input stream
l_streamfactory = l_ixml->create_stream_factory( ).
CALL METHOD l_streamfactory->create_istream_cstring
EXPORTING
string = str_gaeb
RECEIVING
rval = l_istream.
*Create document and parser
l_document = l_ixml->create_document( ).
l_parser = l_ixml->create_parser(
stream_factory = l_streamfactory
istream = l_istream
document = l_document ).
*Parse the XML
IF l_parser->parse( ) NE 0.
IF l_parser->num_errors( ) NE 0.
...
l_parse_error = l_parser->get_error( index = sy-index ).
...
ENDIF.
ENDIF.
l_dom = l_document->get_root_element( ).
EXPORTING
data_as_dom = l_dom
CONTROL =
IMPORTING
dataobject = itab_upload[]
PROBLEMS =
EXCEPTIONS
illegal_object = 1
OTHERS = 2.
IF sy-subrc <> 0.
RAISE import_failture.
ENDIF.
06-29-2007 12:13 PM
Hello Johann,
This has certainly something to with the encoding of the XML you're parsing.
Try to set the encoding type with the method SET_ENCODING of class CL_XML_DOCUMENT before parsing your data.
Otherwise, it is possible to convert data from one codepage to another with the classes
CL_ABAP_CONV_IN_CE, CL_ABAP_CONV_OUT_CE, CL_ABAP_CONV_X2X_CE (These classes quite well documented and contains a lot of information about codepage/encoding translation)
I hope I brought you a little bit further
06-29-2007 12:13 PM
Hello Johann,
This has certainly something to with the encoding of the XML you're parsing.
Try to set the encoding type with the method SET_ENCODING of class CL_XML_DOCUMENT before parsing your data.
Otherwise, it is possible to convert data from one codepage to another with the classes
CL_ABAP_CONV_IN_CE, CL_ABAP_CONV_OUT_CE, CL_ABAP_CONV_X2X_CE (These classes quite well documented and contains a lot of information about codepage/encoding translation)
I hope I brought you a little bit further