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

ST transformation problem XML-ABAP

bernd_speckmann
Contributor
0 Likes
698

Hi there,

I'm trying to use a simple transformation to deserialize a xml-file, but I always get the message that there a root element is expected.

I'm new to simple transformations. So it would be nice, if somebody can help me with this issue.

XML-FILE:

<?xml version="1.0" encoding="UTF-8"?>

<CompactData xmlns="http://www.SDMX.org/resources/SDMXML/schemas/v2_0/message" xmlns:bbk="http://www.bundesbank.de/statistik/zeitreihen/BBKcompact" xmlns:compact="http://www.SDMX.org/resources/SDMXML/schemas/v2_0/compact" xmlns:xsl="http://www.w3.org/2001/XMLSchema-instance" xsl:schemaLocation="http://www.SDMX.org/resources/SDMXML/schemas/v2_0/message schemas/SDMXMessage.xsd http://www.bundesbank.de/statistik/zeitreihen/bbkcompact schemas/BBKCompactData.xsd http://www.SDMX.org/resources/SDMXML/schemas/v2_0/compact schemas/SDMXCompactData.xsd">

  <Header>

    <ID>BBK01_ST0304</ID>

    <Test>false</Test>

    <Truncated>false</Truncated>

    <Prepared>2013-05-03T11:20:03</Prepared>

    <Sender id="BBK">

      <Name xml:lang="de">Deutsche Bundesbank</Name>

      <Contact>

        <Email>[email protected]</Email>

      </Contact>

    </Sender>

  </Header>

  <bbk:DataSet datasetID="BBK01">

    <bbk:Series FREQ="D" BBK_ID="BBK01.ST0304" DECIMALS="3" UNIT="% p.a." UNIT_MULT="0" BBK_TITLE="Geldmarktsätze / EONIA / Tagessatz" BBK_TITLE_ENG="Money market rates / EONIA / Daily quotations" BBK_COMM_GEN="Euro OverNight Index Average: seit 4. Januar 1999 von der Europäischen Zentralbank auf der Basis effektiver Umsätze nach der Zinsmethode act/360 berechneter gewichteter Durchschnittssatz für Tagesgelder im Interbankengeschäft, der von Reuters veröffentlicht wird. Bis 31. August 2007 mit 2 Nachkommastellen veröffentlicht. Weder Euribor EBF, noch Euribor ACI, noch die Referenzbanken, noch das Euribor Steering Committee, noch Reuters, noch die Europäische Zentralbank, noch die Deutsche Bundesbank können bei Unstimmigkeiten des EONIA Satzes haftbar gemacht werden." BBK_COMM_GEN_ENG="Euro OverNight Index Average: weighted average overnight rate for interbank operations calculated by the European Central Bank since 4 January 1999 on the basis of real turnover according to the act/360 method and published via Reuters. Published with 2 decimal points until 31 August 2007. Neither Euribor EBF, nor Euribor ACI, nor the Euribor Panel Banks, nor the Euribor Steering Committee, nor Reuters, nor the European Central Bank, nor the Deutsche Bundesbank can be held liable for any irregularity or inaccuracy of the EONIA rate.">

      <bbk:Obs TIME_PERIOD="2013-04-30" OBS_VALUE="0.102" BBK_DIFF="20.0"/>

      <bbk:Obs TIME_PERIOD="2013-04-29" OBS_VALUE="0.085" BBK_DIFF="3.7"/>

      <bbk:Obs TIME_PERIOD="2013-04-28" BBK_OBS_STATUS="K"/>

      <bbk:Obs TIME_PERIOD="2013-04-27" BBK_OBS_SATUS="K"/>

      <bbk:Obs TIME_PERIOD="2013-04-26" OBS_VALUE="0.082" BBK_DIFF="-1.2"/>

      <bbk:Obs TIME_PERIOD="2013-04-25" OBS_VALUE="0.083" BBK_DIFF="0.0"/>

      <bbk:Obs TIME_PERIOD="2013-04-24" OBS_VALUE="0.083" BBK_DIFF="5.1"/>

      <bbk:Obs TIME_PERIOD="2013-04-23" OBS_VALUE="0.079" BBK_DIFF="-3.7"/>

      <bbk:Obs TIME_PERIOD="2013-04-22" OBS_VALUE="0.082" BBK_DIFF="-1.2"/>

      <bbk:Obs TIME_PERIOD="2013-04-21" BBK_OBS_STATUS="K"/>

      <bbk:Obs TIME_PERIOD="2013-04-20" BBK_OBS_STATUS="K"/>

      <bbk:Obs TIME_PERIOD="2013-04-19" OBS_VALUE="0.083" BBK_DIFF="3.8"/>

      <bbk:Obs TIME_PERIOD="2013-04-18" OBS_VALUE="0.08" BBK_DIFF="2.6"/>

      <bbk:Obs TIME_PERIOD="2013-04-17" OBS_VALUE="0.078" BBK_DIFF="-2.5"/>

      <bbk:Obs TIME_PERIOD="2013-04-16" OBS_VALUE="0.08" BBK_DIFF="-3.6"/>

      <bbk:Obs TIME_PERIOD="2013-04-15" OBS_VALUE="0.083" BBK_DIFF="1.2"/>

      <bbk:Obs TIME_PERIOD="2013-04-14" BBK_OBS_STATUS="K"/>

      <bbk:Obs TIME_PERIOD="2013-04-13" BBK_OBS_STATUS="K"/>

      <bbk:Obs TIME_PERIOD="2013-04-12" OBS_VALUE="0.082" BBK_DIFF="-4.7"/>

      <bbk:Obs TIME_PERIOD="2013-04-11" OBS_VALUE="0.086" BBK_DIFF="4.9"/>

      <bbk:Obs TIME_PERIOD="2013-04-10" OBS_VALUE="0.082" BBK_DIFF="5.1"/>

      <bbk:Obs TIME_PERIOD="2013-04-09" OBS_VALUE="0.078" BBK_DIFF="-4.9"/>

      <bbk:Obs TIME_PERIOD="2013-04-08" OBS_VALUE="0.082" BBK_DIFF="9.3"/>

      <bbk:Obs TIME_PERIOD="2013-04-07" BBK_OBS_STATUS="K"/>

    </bbk:Series>

  </bbk:DataSet>

</CompactData>

Transformation:

<?sap.transform simple?>

<tt:transform xmlns:tt="http://www.sap.com/transformation-templates" xmlns:bbk="http://www.bundesbank.de/statistik/zeitreihen/BBKcompact" xmlns:ddic="http://www.sap.com/abapxml/types/dictionary" xmlns:def="http://www.sap.com/abapxml/types/defined">

  <tt:root name="BBK:SERIES"/>

  <tt:template>

    <ROOT>

      <bbk:Series>

        <tt:loop name="line" ref=".bbk:Series">

          <bbk:Obs>

            <tt:attribute name="TIME_PERIOD">

              <tt:value ref="$line.time_period"/>

            </tt:attribute>

            <tt:attribute name="OBS_VALUE">

              <tt:value ref="$line.obs_value"/>

            </tt:attribute>

            <tt:attribute name="BBK_OBS_STATUS">

              <tt:value ref="$LINE.BBK_OBS_STATUS"/>

            </tt:attribute>

          </bbk:Obs>

        </tt:loop>

      </bbk:Series>

    </ROOT>

  </tt:template>

</tt:transform>

I want to get all element with TIME_PERIOD and OBS_VALUE. The elements without OBS_VALUE should be excluded.

Thank you in advance.

Best Regards

1 REPLY 1
Read only

bernd_speckmann
Contributor
0 Likes
453

Hello,

I've modified my transformation but it still did not work. Would be great if anybody could locate the problem.

The URL of the XML is: http://www.bundesbank.de/cae/servlet/StatisticDownload?tsId=BBK01.ST0304&its_fileFormat=sdmx&mode=it...

I read the XML with this ABAP:

DATA: lo_http_client TYPE REF TO IF_HTTP_CLIENT.

DATA: lv_str TYPE XSTRING,

      lv_i TYPE I.

CALL METHOD cl_http_client=>create_by_url

  EXPORTING

     url                = 'http://www.bundesbank.de/cae/servlet/StatisticDownload?tsId=BBK01.ST0304&its_fileFormat=sdmx&mode=it...'

  IMPORTING

    client             = lo_http_client

  EXCEPTIONS

    argument_not_found = 1

    plugin_not_active  = 2

    internal_error     = 3.

CHECK sy-subrc = 0.

lo_http_client->propertytype_logon_popup = lo_http_client->co_disabled.

lo_http_client->request->set_header_field( EXPORTING name  = '~request_method'

                                                     value = 'GET' ).

lo_http_client->request->set_header_field( EXPORTING name  = '~server_protocol'

                                                     value = 'HTTP/1.1' ).

CALL METHOD lo_http_client->send

  EXCEPTIONS

    http_communication_failure = 1

    http_invalid_state         = 2.

CHECK sy-subrc = 0.

CALL METHOD lo_http_client->receive

  EXCEPTIONS

    http_communication_failure = 1

    http_invalid_state         = 2

    http_processing_failed     = 3.

CHECK sy-subrc = 0.

lo_http_client->response->get_status( IMPORTING code = lv_i ).

CHECK lv_i = 200.

lv_str = lo_http_client->response->get_data( ).

The new ST transformation is as follows:

<?sap.transform simple?>

<tt:transform xmlns:tt="http://www.sap.com/transformation-templates">

  <tt:root name="ABAP_ZINSDATA"/>

  <tt:root name="ABAP_ID"/>

  <tt:root name="ABAP_TEST"/>

  <tt:root name="ABAP_TRUNCATED"/>

  <tt:root name="ABAP_PREPARED"/>

  <tt:root name="ABAP_SENDER"/>

  <tt:root name="ABAP_NAME"/>

  <tt:root name="ABAP_EMAIL"/>

  <tt:template name="MAIN">

    <CompactData>

      <Header>

        <ID>

          <tt:value ref=".ABAP_ID"/>

        </ID>

        <Test>

          <tt:value ref=".ABAP_TEST"/>

        </Test>

        <Truncated>

          <tt:value ref=".ABAP_TRUNCATED"/>

        </Truncated>

        <Prepared>

          <tt:value ref=".ABAP_PREPARED"/>

        </Prepared>

        <Sender>

          <tt:attribute ref=".ABAP_SENDER" name="sender"/>

          <Name>

            <tt:attribute ref=".ABAP_NAME" name="name"/>

          </Name>

          <Contact>

            <Email>

              <tt:value ref=".ABAP_EMAIL"/>

            </Email>

          </Contact>

        </Sender>

      </Header>

      <DataSet>

        <Series>

          <tt:loop name="zeile" ref=".ABAP_ZINSDATA">

            <Obs>

              <tt:attribute name="TIME_PERIOD" ref="$zeile.ABAP_TIME_PERIOD"/>

              <tt:attribute name="OBS_VALUE" ref="$zeile.ABAP_OBS_VALUE"/>

              <tt:attribute name="BBK_OBS_STATUS" ref="$zeile.ABAP_OBS_STATUS"/>

            </Obs>

          </tt:loop>

        </Series>

      </DataSet>

    </CompactData>

  </tt:template>

</tt:transform>

When I try to transform (deserialize) it the following error occures:

Element 'CompactData' erwartet

Thanks in advance!