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: 

Simple Transformation - deserialization - Match Element Error

0 Kudos
2,149

I have to parse the following XML into an internal table, I get the short dump, after running the program. Please see the program and simple transformation in the following. An exception occurred in simple transformation that is explained in detail below.

The exception, which is assigned to class 'CX_ST_MATCH_ELEMENT', was not caught and therefore caused a runtime error.

The reason for the exception is:

XML matching error Expected was element-end: "Total" [ ] Read was element-start: "Weighing"

Please someone of you help me to correct my program, I am stuck at the moment.

Many thanks in advance

REPORT ZPP_TT_EXAMPLETEST_ST.
DATA itab1 TYPE string.
CONCATENATE '<Automatic>'
'        <Weighing Tolerance="5" Deviation="1.60" >'
'          <Substance ExtId="3"   Speed="1" />'
'          <Substance ExtId="22"  Speed="5" />'
'        </Weighing>'
'        <Weighing Tolerance="5" Deviation="-16" >'
'          <Substance ExtId="22" Speed="5" />'
'        </Weighing>'
'        <Weighing  Tolerance="5" >'
'          <Substance ExtId="22" Speed="5" />'
'        </Weighing>'
'       <Total State="0" Result="Ok" />'
'      </Automatic>'
INTO itab1.

* Substance *
TYPES: BEGIN OF ty_data,
         ExtId  TYPE CHAR20,
         Speed TYPE CHAR20,
       END OF ty_data.
DATA: wa_ty_data TYPE ty_data.
DATA: lt_data TYPE TABLE OF ty_data.

* Total *
TYPES: BEGIN OF ty_data3,
         State  TYPE CHAR20,
         Result TYPE CHAR20,
       END OF ty_data3.
DATA: wa_ty_data3 TYPE ty_data3.
DATA: lt_data3 TYPE TABLE OF ty_data3.

* Weighing *
TYPES: BEGIN OF ty_data2,
         Tolerance  TYPE CHAR20,
         Deviation  TYPE CHAR20,
         t_data     TYPE TABLE OF ty_data WITH DEFAULT KEY,
         t_data3    TYPE TABLE OF ty_data3 WITH DEFAULT KEY,
       END OF ty_data2.
DATA: wa_ty_data2 TYPE ty_data2.
DATA: lt_data2 TYPE TABLE OF ty_data2.

CALL TRANSFORMATION zpp_tt_exampletest_st
      SOURCE XML itab1
      RESULT xml_tab = lt_data2.


<?sap.transform simple?>
<tt:transform xmlns:tt="http://www.sap.com/transformation-templates">
  <tt:root name="XML_TAB"/>
  <tt:template>
    <Automatic>
      <tt:loop name="b" ref=".XML_TAB">
        <Weighing>
          <tt:cond check="not-initial($b.TOLERANCE)">
            <tt:attribute name="Tolerance" value-ref="$b.TOLERANCE"/>
          </tt:cond>
          <tt:cond check="not-initial($b.DEVIATION)">
            <tt:attribute name="Deviation" value-ref="$b.DEVIATION"/>
          </tt:cond>
          <tt:loop name="a" ref="$b.T_DATA">
            <Substance>
              <tt:cond check="not-initial($a.EXTID)">
                <tt:attribute name="ExtId" value-ref="$a.EXTID"/>
              </tt:cond>
              <tt:cond check="not-initial($a.SPEED)">
                <tt:attribute name="Speed" value-ref="$a.SPEED"/>
              </tt:cond>
            </Substance>
          </tt:loop>
          <Total>
            <tt:cond check="not-initial($b.STATE)">
              <tt:attribute name="State" value-ref="$b.STATE"/>
            </tt:cond>
            <tt:cond check="not-initial($b.RESULT)">
              <tt:attribute name="Result" value-ref="$b.RESULT"/>
            </tt:cond>
          </Total>
        </Weighing>
      </tt:loop>
    </Automatic>
  </tt:template>
</tt:transform>

5 REPLIES 5

DoanManhQuynh
Active Contributor
0 Kudos
580

Hi.

Did you try <Total> </Total> instead of <Total /> ?

If there is any tag not defined in your template, its also raised 'CX_ST_MATCH_ELEMENT'. you can read this link:

https://help.sap.com/saphelp_nw70/helpdata/en/a5/c2ef412f695f24e10000000a1550b0/content.htm?no_cache...

0 Kudos
580

Hi Quynh,

Thanks for your response.

As you have suggested, I have tried <Total> </Total> instead of <Total /> in my input XML stream, it didn't work.

If you meant to try <Total> </Total> instead of <Total /> in simple transformation, I don't know how to do it?? Please can you elaborate it or help me with another suggestion.

Looking forward to your reply.

0 Kudos
580

Hi Tariq.

Sorry I take a look in your xml in itab1 and transformation again and find out the error reason is not about tag reconization but the order of the xml template and transformation template.

As your transformation, node Total is a child of Weighing but in your xml template Total is separate with Weighing. If your xml and transformation didnt match, it would rise the exception.

I change the code like this and it pass through that exception (but I dont have data in lt_data2 so it raise another exception, that you can check by yourself):

ABAP:

XML_T = VALUE #( ( '<Automatic>' )
( '<Weighing Tolerance="5" Deviation="1.60" >' )
( '<Substance ExtId="3" Speed="1" />' )
( '<Substance ExtId="22" Speed="5" />' )
( '<Total State="0" Result="Ok" />' )
( '</Weighing>' )
( '<Weighing Tolerance="5" Deviation="-16" >' )
( '<Substance ExtId="22" Speed="5" />' )
( '</Weighing>' )
( '<Weighing Tolerance="5" >' )
( '<Substance ExtId="22" Speed="5" />' )
( '</Weighing>' )
* ( '<Total State="0" Result="Ok" />' )
( '</Automatic>' ) ).

0 Kudos
580

Hi Quynh,

Thanks for your efforts. But your answer doesn't work in my problem.

My XML Template is correct, in which <Weighing> and <Total>, both are children nodes of <Automatic>, and are on same level. <Weighing> contains one child node <Substance> and <Total> is not child node of <Weighing>.

I know, I have a problem in my Simple Transformation, but not in my XML Template. Please point out my mistake in Simple transformation. I have to parse the above mentioned XML by writing a error free Simple Transformation program, not the other way around (you have changed and adjusted my XML template in order to work my simple transformation).

I have tried in many different ways to solve this problem since last one week, but nothing work so far.

Looking forward to your reply.


0 Kudos
580

Sorry Tariq for late reply. I didnt see notification.

You said <Weighing> and <Total> are in same level but let look at your simple transformation, after loop to get Substance you didnt close <Weighing> but get data for Total node, in that way Total become child of Weighing right?. Then you need to fix the transformation.