Application Development 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: 

XML with Open Dataset - Special Characters! (cl_xml_document)

marcushautz
Explorer
0 Kudos

I need to create an XML Document in ABAP and download the data to a text file in XML format on the application server. The problem is, that special characters like ä,ö,ü (german) get replaced by some wierd codes...

I managed to create the XML file with the class CL_XML_DOCUMENT and if I use the method EXPORT_TO_FILE it works fine - but only on the presentation server... If I use the method GET_AS_TABLE (in xstring) format, I get the data, but all Special Characters are messed up and the xml file is not readable.

I basically need to extract the data from CL_XML_DOCUMENT in string form without losing the special characters.

Here is a demo program I wrote, to show you the problem in simple form. ("Müller" becomes "Müller").

-

-


snip----


snip----


snip----

-


TYPES: BEGIN OF xml_line,

data(256) TYPE x,

END OF xml_line.

DATA: ref_xml_doc TYPE REF TO cl_xml_document,

l_head TYPE REF TO if_ixml_node,

l_dataset TYPE REF TO if_ixml_node,

l_node TYPE REF TO if_ixml_node,

l_xml_table TYPE TABLE OF xml_line,

l_xml_line type xml_line,

l_size TYPE i,

l_rc TYPE sysubrc,

l_filename(132) type c.

CREATE OBJECT ref_xml_doc.

  • --- Create Header ---

l_head = ref_xml_doc->create_simple_element( name = 'HEAD' ).

  • --- Set Attributes on Header ---

CALL METHOD ref_xml_doc->set_attribute( name = 'Version'

value = '1.0'

node = l_head ).

  • --- Create Data Header Node ---

l_dataset = ref_xml_doc->create_simple_element(

name = 'DATASET' parent = l_head ).

  • --- Create Data Field under Data Header Node ---

l_node = ref_xml_doc->create_simple_element(

name = 'LastName'

value = 'Müller'

parent = l_dataset ).

  • --- Save the XML Document as local file --- THIS WORKS!

CALL METHOD ref_xml_doc->export_to_file

EXPORTING filename = 'h: est1.xml'.

  • --- Get the XML Document as internal Table ---

CALL METHOD ref_xml_doc->get_as_table

IMPORTING

table = l_xml_table " XString Chars broken!

size = l_size

retcode = l_rc.

  • --- Open File for Output on Appl.Server ---

l_filename = '/usr/tmp/test1.xml'.

open dataset l_filename for output in binary mode.

  • --- Transfer the Data in Binary Mode ---

loop at l_xml_table into l_xml_line.

transfer l_xml_line to l_filename.

endloop.

close dataset l_filename.

-

-


snip----


snip----


snip----

-


Additions:

1. We have Release 4.6c so, no "Encoding" Option in the OPEN DATASET and no suitable methods in cl_xml_document.

2. I tried SDIXML_DOM_TO_XML, didnt work.

Any help will be greatly appreciated. Thanks !

Marcus Hautz

3 REPLIES 3

Peter_Inotai
Active Contributor
0 Kudos

I think you have to make sure that you use the same codepage everywhere (application server, your PC, etc)

What if you download via ftp and not via your SAP GUI?

Peter

0 Kudos

Hello Peter !

I am not sure about the codepage, but I think it is already setup the right way. AFAIK it is not possible to send an internal table from the ABAP code via FTP to the application server. The problem is, that the internal table I get from CL_XML_DOCUMENT is already messed up. That means I get it as XSTRING and when I convert it to STRING the special characters are damaged. Anyways, if I download the table in binary mode (as XSTRING) to my frontend with WS_DOWNLOAD, the special characters are all fine ! Only the OPEN DATASET is not able to save the XSTRING without losing the ä,ö,ü ...

I wish we had a newer release, so I could use the additional options of Open Dataset, but that's not possible at the moment. So any other ideas ?

Thanks in advance,

Marcus Hautz

-

-


Output with OPEN DATASET

0 Kudos

just store the XSTRING in application server with open data set with binary mode option. i guess this wouldnt mess up the contents.

Regards

Raja