Skip to Content
author's profile photo Former Member
Former Member

Simple XML Transformation: Dump on converting several elements into xstring

Hi all,

I'm having troubles to use a simple transformation that creates a byte-string (xstring) as result. It is necessary for me to use a byte-string to have xml in UTF-8 format, because I need to transport data in file format between unicode and non-unicode systems.

I even tried to do things as simple as possible and took the SAP Example for simple transformations and just modified the result type...

* The code of the simple transformation
<?sap.transform simple?>
<tt:transform xmlns:tt="http://www.sap.com/transformation-templates" template="temp1" version="0.1">
  <tt:root name="PARA1"/>
  <tt:root name="PARA2"/>
  <tt:template name="temp1">
    <X1>
      <tt:value ref="PARA1"/>
    </X1>
    <X2>
      <tt:value ref="PARA2"/>
    </X2>
  </tt:template>
</tt:transform>
* Simple Transformation with xstring result
DATA xml_string TYPE xstring.
DATA field1(10) TYPE c VALUE 'Field1'.
DATA field2(10) TYPE c VALUE 'Field2'.

CALL TRANSFORMATION zst_demo
  SOURCE para1 = field1
         para2 = field2
  RESULT XML xml_string.

DATA result1 LIKE field1.
DATA result2 LIKE field2.

CALL TRANSFORMATION zst_demo
  SOURCE XML xml_string
  RESULT para1 = result1
         para2 = result2.

When executing the code and using a string as result everything works fine, but when using a xstring I get a dump considering "ST_INVALID_XML" with action "OpenElement". Converting only one data element works fine with an xstring, but when trying to convert 2 parameters I get that dump.

Any hints or another post with information on how to solve this?

Kind regards, Karsten

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • author's profile photo Former Member
    Former Member
    Posted on Feb 05, 2007 at 04:18 PM

    Try this,

    data: g_ixml type ref to if_ixml,
            g_stream_factory type ref to if_ixml_stream_factory,
            g_encoding type ref to if_ixml_encoding,
            ostream type ref to if_ixml_ostream.
    
    DATA xml_string TYPE xstring.
    DATA field1(10) TYPE c VALUE 'Field1'.
    DATA field2(10) TYPE c VALUE 'Field2'.
    constants: encoding type string value `utf-8`.
    
    g_ixml = cl_ixml=>create( ).
    g_stream_factory = g_ixml->create_stream_factory( ).
    g_encoding = g_ixml->create_encoding( character_set = encoding
                                                               byte_order = 0 ).
    
    ostream = g_stream_factory->create_ostream_xstring( string = xml_string ).
    ostream->set_encoding( encoding = g_encoding ).
    
    CALL TRANSFORMATION zst_demo
      SOURCE para1 = field1
                    para2 = field2
      RESULT XML ostream.
    

    This should work and you will have the xstring result in xml_string.

    Suman

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.