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

Read XML from a String

Former Member
0 Likes
501

Hi, I have called a Web Service that return an XML Sting. This is the abap code:



REPORT  zprova_proxy line-SIZE 1000.

DATA: proxy TYPE REF TO zco_service1soap.
DATA: intab  TYPE zget_dati_vestiariosoap_in.
DATA: output TYPE zget_dati_vestiariosoap_out.
DATA : sys_fault TYPE REF TO cx_ai_system_fault.


CREATE OBJECT proxy
  EXPORTING
    logical_port_name = 'PORTA'.
IF sy-subrc EQ 0.
  TRY.
      CALL METHOD proxy->get_dati_vestiario
        EXPORTING
          input  = intab
        IMPORTING
          output = output.
    CATCH cx_ai_system_fault .
      CREATE OBJECT sys_fault.
      WRITE :/ 'error at level 1', sys_fault->errortext.
      EXIT.
    CATCH cx_ai_application_fault .
  ENDTRY.



ENDIF.


WRITE /: output-get_dati_vestiarioresult.

When I write the output field I have an XML String.

Now I want to access XML tags "<elenco></elenco>" of my String and fill an internal table. How can I do it?

Help me please. THANKS

Edited by: Andrea Ruocco on Jun 17, 2009 5:51 PM

Edited by: Andrea Ruocco on Jun 17, 2009 5:53 PM

1 ACCEPTED SOLUTION
Read only

naimesh_patel
Active Contributor
0 Likes
433

You need to create a XSLT Transformation and call that by passing your XML string and get the internal table.


DATA: lf_string TYPE string.
DATA: xml_string TYPE string.

lf_string = 'This single variable test'.

TRY.

* This call gets me the XML data. You need to skip this as you 
* already have the XML string
    CALL TRANSFORMATION ztest_np_xml2data
      SOURCE if_test = lf_string
      RESULT XML xml_string.

    CLEAR lf_string.

    CALL TRANSFORMATION ztest_np_xml2data
      SOURCE XML xml_string
      RESULT if_test = lf_string.

  CATCH cx_st_error.

ENDTRY.

Transformation ZTEST_NP_XML2DATA


<?sap.transform simple?>
<tt:transform template="temp"
    xmlns:tt="http://www.sap.com/transformation-templates"
    version="0.1">

  <tt:root name="IF_TEST"/>

  <tt:template name="temp">
    <Test>
        <tt:value ref="IF_TEST" />
    </Test>
  </tt:template>

</tt:transform>

Check this example from Help: http://help.sap.com/saphelp_nw2004s/helpdata/en/a4/1f1e400191f72ee10000000a1550b0/frameset.htm

Regards,

Naimesh Patel

1 REPLY 1
Read only

naimesh_patel
Active Contributor
0 Likes
434

You need to create a XSLT Transformation and call that by passing your XML string and get the internal table.


DATA: lf_string TYPE string.
DATA: xml_string TYPE string.

lf_string = 'This single variable test'.

TRY.

* This call gets me the XML data. You need to skip this as you 
* already have the XML string
    CALL TRANSFORMATION ztest_np_xml2data
      SOURCE if_test = lf_string
      RESULT XML xml_string.

    CLEAR lf_string.

    CALL TRANSFORMATION ztest_np_xml2data
      SOURCE XML xml_string
      RESULT if_test = lf_string.

  CATCH cx_st_error.

ENDTRY.

Transformation ZTEST_NP_XML2DATA


<?sap.transform simple?>
<tt:transform template="temp"
    xmlns:tt="http://www.sap.com/transformation-templates"
    version="0.1">

  <tt:root name="IF_TEST"/>

  <tt:template name="temp">
    <Test>
        <tt:value ref="IF_TEST" />
    </Test>
  </tt:template>

</tt:transform>

Check this example from Help: http://help.sap.com/saphelp_nw2004s/helpdata/en/a4/1f1e400191f72ee10000000a1550b0/frameset.htm

Regards,

Naimesh Patel