简体   繁体   English

ABAP简单转换中的CX_ST_MATCH_ELEMENT

[英]CX_ST_MATCH_ELEMENT in ABAP Simple Transformation

I am trying to transform a simple XML to ABAP and use the transaction XSLT_TOOL .我正在尝试将简单的 XML 转换为 ABAP 并使用事务XSLT_TOOL The dump I get我得到的转储

Errores tiempo ejec.错误时间弹出。 ST_MATCH_FAIL Excepción ST_MATCH_FAIL 异常
CX_ST_MATCH_ELEMENT Fecha y hora 31.07.2017 18:55:46 CX_ST_MATCH_ELEMENT Fecha y hora 31.07.2017 18:55:46

XML: XML:

<?xml version="1.0" encoding="UTF-8"?>
<objects type="array">
    <object>
        <transaction-id type="integer">28</transaction-id>
        <message type="symbol">FAILURE</message>
        <errors type="array">
            <error>
                <row type="integer">0</row>
                <field>Sin datos</field>
                <message>El Json no puede estar en blanco.</message>
            </error>
        </errors>
    </object>
</objects>

xslt_工具

在此处输入图像描述

This is the generated by the program:这是程序生成的:

<tt:transform xmlns:tt="http://www.sap.com/transformation-templates" xmlns:ddic="http://www.sap.com/abapxml/types/dictionary" xmlns:def="http://www.sap.com/abapxml/types/defined">   <tt:root name="ZDGR2_RETORNOINVOCACION" type="ddic:ZDGR2_RETORNOINVOCACION"/>   <tt:template>
    <ZDGR2_RETORNOINVOCACION>
      <MESSAGE tt:value-ref=".ZDGR2_RETORNOINVOCACION.MESSAGE"/>
      <TRANSACTION_ID tt:value-ref=".ZDGR2_RETORNOINVOCACION.TRANSACTION_ID"/>
      <ERRORS>
        <tt:loop ref=".ZDGR2_RETORNOINVOCACION.ERRORS">
          <ZDGR2_ERRORS>
            <FILA tt:value-ref="FILA"/>
            <FIELD tt:value-ref="FIELD"/>
            <MESSAGE tt:value-ref="MESSAGE"/>
          </ZDGR2_ERRORS>
        </tt:loop>
      </ERRORS>
    </ZDGR2_RETORNOINVOCACION>   
</tt:template> </tt:transform>

This the simple program:这是一个简单的程序:

DATA: lv_xml Type string. 
DATA: it_resultado type ZDGR2_RETORNOINVOCACION. 
CONCATENATE '<?xml version="1.0" encoding="UTF-8"?><objects type="array"><object><transaction-id type="integer">28</transaction-id><message type="symbol">FAILURE</message><errors type="array"><error><row type="integer">0</row><field>Sin datos</field>' '<message>El Json no puede estar en blanco.</message></error></errors></object></objects>' INTO lv_xml. 

CALL TRANSFORMATION zdgr2_retornoinvocacion
     SOURCE XML lv_xml
     RESULT zdgr2_retornoinvocacion = it_resultado.

What am I doing wrong?我究竟做错了什么?

This dump happens when the tags in the XML not have the same name or order as in the transformation.当 XML 中的标签与转换中的标签名称或顺序不同时,就会发生此转储。

In your example i see multible problems:在您的示例中,我看到了多个问题:

Your XML structure starts like this:您的 XML 结构是这样开始的:

<object>
   <transaction-id type="integer">28</transaction-id>
   <message type="symbol">FAILURE</message>

But your Transformation starts like this:但是你的转型是这样开始的:

<ZDGR2_RETORNOINVOCACION>
  <MESSAGE tt:value-ref=".ZDGR2_RETORNOINVOCACION.MESSAGE"/> 
  <TRANSACTION_ID tt:value-ref=".ZDGR2_RETORNOINVOCACION.TRANSACTION_ID"/>

So in my opinion <ZDGR2_RETORNOINVOCACION> should be named <object> and <MESSAGE> and <TRANSACTION_ID> have to be swaped.所以在我看来<ZDGR2_RETORNOINVOCACION>应该被命名为<object>并且<MESSAGE><TRANSACTION_ID>必须被交换。

Also in the error substructure you have some missmatches同样在错误子结构中你有一些不匹配

 <error>
     <row type="integer">0</row>
     <field>Sin datos</field>
     <message>El Json no puede estar en blanco.</message>
  </error>

<ZDGR2_ERRORS>
     <FILA tt:value-ref="FILA"/>
     <FIELD tt:value-ref="FIELD"/>
     <MESSAGE tt:value-ref="MESSAGE"/>
</ZDGR2_ERRORS>

<ZDGR2_ERRORS> should be named <error> and <FILA> should be named <row> . <ZDGR2_ERRORS>应命名为<error>并且<FILA>应命名为<row>

So the important rule is that the tags have the same name and order in the xml file (its not case sensitive so it does not matter if its <OBJECT> or <object> ).所以重要的规则是标签在 xml 文件中具有相同的名称和顺序(它不区分大小写,所以它是<OBJECT>还是<object>并不重要)。

A advice from my side is, you can debug the transformation.我的建议是,您可以调试转换。 Go through step by step and by the tag it dumps most of the times the name or the order is not ok.一步一步地通过它转储的标签,大多数时候名称或顺序不正确。 So you can find the errors fast and you dont have to compare the whole xml structure.因此您可以快速找到错误,而不必比较整个 xml 结构。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM