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: 

SAP Simple Transformation Deserialize : Strange result with namespace xmlns

YouriC
Participant

Hi,

I'm trying to deserialize an XML file.
In this XML file I have some useless <tag> : <bob1> and <bob2>.

This XML doesn't work

<Invoice xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2">
<Bob1>Blablabla</Bob1>
<ID>001</ID>
<EndpointID schemeID="0208">1234567890</EndpointID>
<Bob2>450</Bob2>
</Invoice>

And this one is OK

<Invoice test="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2">
<Bob1>Blablabla</Bob1>
<ID>001</ID>
<EndpointID schemeID="0208">1234567890</EndpointID>
<Bob2>450</Bob2>
</Invoice>

The only difference is the prefix xmlns on the <Invoice> line, replaced by test in the second.

My SP is :

<?sap.transform simple?>
<tt:transform xmlns:tt="http://www.sap.com/transformation-templates" xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" xmlns:ddic="http://www.sap.com/abapxml/types/dictionary" xmlns:def=
"http://www.sap.com/abapxml/types/defined">
<tt:root name="INVOICE"/>

<tt:template>
<Invoice xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2">
<tt:skip count="1" name="Bob1"/>
<ID tt:value-ref="INVOICE.ID"/>
<EndpointID>
<tt:attribute name="schemeID" value-ref="INVOICE.ENDPOINTID_SID"/>
<tt:value ref="INVOICE.ENDPOINTID"/>
</EndpointID>
<tt:skip count="1" name="Bob2"/>
</Invoice>
</tt:template>

</tt:transform>
XML 1 <Invoice xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2"> : Error
Xml 2 <Invoice test="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2"> : OK

In my SP when I try with the prefix "xmlns" with the first XML I have an Exception.
If I replace by "Test" and try with my second XML > No problem.

Of course the data in my example makes no sense, it's for the example.
With the production data, I'm going to have a lot of prefixes... and the Invoice line will be as in my first XML file (with xmlns).

Do you have an idea about this problem ?

Regards,
Youri

1 ACCEPTED SOLUTION

Sandra_Rossi
Active Contributor

I guess you have a CX_ST_MATCH_ELEMENT with message "System expected element 'Bob1'".

I reproduce the error message with your code + a few data completed:

    TYPES: BEGIN OF ty_transfo_result,
             id             TYPE string,
             endpointid_sid TYPE string,
             endpointid     TYPE string,
           END OF ty_transfo_result.
    transfo_name = create_transfo( concat_lines_of( sep = |\r\n| table = VALUE string_table(
              ( `<?sap.transform simple?>                                                        ` )
              ( `<tt:transform                                                                   ` )
              ( `xmlns:tt="http://www.sap.com/transformation-templates"                          ` )
              ( `xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2"` )
              ( `xmlns:ddic="http://www.sap.com/abapxml/types/dictionary"                        ` )
              ( `xmlns:def="http://www.sap.com/abapxml/types/defined">                           ` )
              ( `  <tt:root name="INVOICE"/>                                                     ` )
              ( `                                                                                ` )
              ( `  <tt:template>                                                                 ` )
              ( `    <Invoice xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2">    ` )
              ( `      <tt:skip count="1" name="Bob1"/>                                          ` )
              ( `      <ID tt:value-ref="INVOICE.ID"/>                                           ` )
              ( `      <EndpointID>                                                              ` )
              ( `        <tt:attribute name="schemeID" value-ref="INVOICE.ENDPOINTID_SID"/>      ` )
              ( `        <tt:value ref="INVOICE.ENDPOINTID"/>                                    ` )
              ( `      </EndpointID>                                                             ` )
              ( `      <tt:skip count="1" name="Bob2"/>                                          ` )
              ( `    </Invoice>                                                                  ` )
              ( `  </tt:template>                                                                ` )
              ( `                                                                                ` )
              ( `</tt:transform>                                                                 ` ) ) ) ).
    DATA(transfo_result) = VALUE ty_transfo_result( ).
    DATA(xml) ='<Invoice xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2">'
            && '  <Bob1>Blablabla</Bob1>                                                '
            && '  <ID>001</ID>                                                          '
            && '  <EndpointID schemeID="0208">1234567890</EndpointID>                   '
            && '  <Bob2>450</Bob2>                                                      '
            && '</Invoice>                                                              '.
    CALL TRANSFORMATION (transfo_name)
        SOURCE XML xml
        RESULT invoice = transfo_result.
    cl_abap_unit_assert=>assert_equals(
        act = transfo_result
        exp = VALUE ty_transfo_result(
            id             = '001'
            endpointid_sid = '0208'
            endpointid     = '1234567890' ) ).

To make it work, there are 2 solutions:

  1. either you simply omit skip by making use of tt:extensible="deep-dynamic" (among other possible values)
  2. or you use a dummy namespace prefix as shown below (use whatever prefix name you want)

Solution 1 with tt:extensible="deep-dynamic":

    TYPES: BEGIN OF ty_transfo_result,
             id             TYPE string,
             endpointid_sid TYPE string,
             endpointid     TYPE string,
           END OF ty_transfo_result.
    transfo_name = create_transfo( concat_lines_of( sep = |\r\n| table = VALUE string_table(
              ( `<?sap.transform simple?>                                                        ` )
              ( `<tt:transform                                                                   ` )
              ( `xmlns:tt="http://www.sap.com/transformation-templates"                          ` )
              ( `xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2"` )
              ( `xmlns:ddic="http://www.sap.com/abapxml/types/dictionary"                        ` )
              ( `xmlns:def="http://www.sap.com/abapxml/types/defined">                           ` )
              ( `  <tt:root name="INVOICE"/>                                                     ` )
              ( `                                                                                ` )
              ( `  <tt:template>                                                                 ` )
              ( `    <Invoice xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2"     ` )
              ( `        tt:extensible="deep-dynamic">                                           ` )
              ( `      <ID tt:value-ref="INVOICE.ID"/>                                           ` )
              ( `      <EndpointID>                                                              ` )
              ( `        <tt:attribute name="schemeID" value-ref="INVOICE.ENDPOINTID_SID"/>      ` )
              ( `        <tt:value ref="INVOICE.ENDPOINTID"/>                                    ` )
              ( `      </EndpointID>                                                             ` )
              ( `    </Invoice>                                                                  ` )
              ( `  </tt:template>                                                                ` )
              ( `                                                                                ` )
              ( `</tt:transform>                                                                 ` ) ) ) ).
    DATA(transfo_result) = VALUE ty_transfo_result( ).
    DATA(xml) ='<Invoice xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2">'
            && '  <Bob1>Blablabla</Bob1>                                                '
            && '  <ID>001</ID>                                                          '
            && '  <EndpointID schemeID="0208">1234567890</EndpointID>                   '
            && '  <Bob2>450</Bob2>                                                      '
            && '</Invoice>                                                              '.
    CALL TRANSFORMATION (transfo_name)
        SOURCE XML xml
        RESULT invoice = transfo_result.
    cl_abap_unit_assert=>assert_equals(
        act = transfo_result
        exp = VALUE ty_transfo_result(
            id             = '001'
            endpointid_sid = '0208'
            endpointid     = '1234567890' ) ).


Solution 2 with dummy namespace prefix:

    TYPES: BEGIN OF ty_transfo_result,
             id             TYPE string,
             endpointid_sid TYPE string,
             endpointid     TYPE string,
           END OF ty_transfo_result.
    transfo_name = create_transfo( concat_lines_of( sep = |\r\n| table = VALUE string_table(
              ( `<?sap.transform simple?>                                                        ` )
              ( `<tt:transform                                                                   ` )
              ( `xmlns:tt="http://www.sap.com/transformation-templates"                          ` )
              ( `xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2"` )
              ( `xmlns:ddic="http://www.sap.com/abapxml/types/dictionary"                        ` )
              ( `xmlns:def="http://www.sap.com/abapxml/types/defined">                           ` )
              ( `  <tt:root name="INVOICE"/>                                                     ` )
              ( `                                                                                ` )
              ( `  <tt:template>                                                                 ` )
              ( `    <Invoice xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2"     ` )
              ( `        xmlns:dummy="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2">   ` )
              ( `      <tt:skip count="1" name="dummy:Bob1"/>                                    ` )
              ( `      <ID tt:value-ref="INVOICE.ID"/>                                           ` )
              ( `      <EndpointID>                                                              ` )
              ( `        <tt:attribute name="schemeID" value-ref="INVOICE.ENDPOINTID_SID"/>      ` )
              ( `        <tt:value ref="INVOICE.ENDPOINTID"/>                                    ` )
              ( `      </EndpointID>                                                             ` )
              ( `      <tt:skip count="1" name="dummy:Bob2"/>                                    ` )
              ( `    </Invoice>                                                                  ` )
              ( `  </tt:template>                                                                ` )
              ( `                                                                                ` )
              ( `</tt:transform>                                                                 ` ) ) ) ).
    DATA(transfo_result) = VALUE ty_transfo_result( ).
    DATA(xml) ='<Invoice xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2">'
            && '  <Bob1>Blablabla</Bob1>                                                '
            && '  <ID>001</ID>                                                          '
            && '  <EndpointID schemeID="0208">1234567890</EndpointID>                   '
            && '  <Bob2>450</Bob2>                                                      '
            && '</Invoice>                                                              '.
    CALL TRANSFORMATION (transfo_name)
        SOURCE XML xml
        RESULT invoice = transfo_result.
    cl_abap_unit_assert=>assert_equals(
        act = transfo_result
        exp = VALUE ty_transfo_result(
            id             = '001'
            endpointid_sid = '0208'
            endpointid     = '1234567890' ) ).
6 REPLIES 6

Sandra_Rossi
Active Contributor

I guess it's the same question as this one: XML deserialization: error tt:skip and namespaces | SAP Community

(see my second answer concerning <data xmlns="urn:mynamespace" xmlns:aaaaaaa="urn:mynamespace"> ... <tt:skip name="aaaaaaa:X2"/>)

Sandra_Rossi
Active Contributor

I guess you have a CX_ST_MATCH_ELEMENT with message "System expected element 'Bob1'".

I reproduce the error message with your code + a few data completed:

    TYPES: BEGIN OF ty_transfo_result,
             id             TYPE string,
             endpointid_sid TYPE string,
             endpointid     TYPE string,
           END OF ty_transfo_result.
    transfo_name = create_transfo( concat_lines_of( sep = |\r\n| table = VALUE string_table(
              ( `<?sap.transform simple?>                                                        ` )
              ( `<tt:transform                                                                   ` )
              ( `xmlns:tt="http://www.sap.com/transformation-templates"                          ` )
              ( `xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2"` )
              ( `xmlns:ddic="http://www.sap.com/abapxml/types/dictionary"                        ` )
              ( `xmlns:def="http://www.sap.com/abapxml/types/defined">                           ` )
              ( `  <tt:root name="INVOICE"/>                                                     ` )
              ( `                                                                                ` )
              ( `  <tt:template>                                                                 ` )
              ( `    <Invoice xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2">    ` )
              ( `      <tt:skip count="1" name="Bob1"/>                                          ` )
              ( `      <ID tt:value-ref="INVOICE.ID"/>                                           ` )
              ( `      <EndpointID>                                                              ` )
              ( `        <tt:attribute name="schemeID" value-ref="INVOICE.ENDPOINTID_SID"/>      ` )
              ( `        <tt:value ref="INVOICE.ENDPOINTID"/>                                    ` )
              ( `      </EndpointID>                                                             ` )
              ( `      <tt:skip count="1" name="Bob2"/>                                          ` )
              ( `    </Invoice>                                                                  ` )
              ( `  </tt:template>                                                                ` )
              ( `                                                                                ` )
              ( `</tt:transform>                                                                 ` ) ) ) ).
    DATA(transfo_result) = VALUE ty_transfo_result( ).
    DATA(xml) ='<Invoice xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2">'
            && '  <Bob1>Blablabla</Bob1>                                                '
            && '  <ID>001</ID>                                                          '
            && '  <EndpointID schemeID="0208">1234567890</EndpointID>                   '
            && '  <Bob2>450</Bob2>                                                      '
            && '</Invoice>                                                              '.
    CALL TRANSFORMATION (transfo_name)
        SOURCE XML xml
        RESULT invoice = transfo_result.
    cl_abap_unit_assert=>assert_equals(
        act = transfo_result
        exp = VALUE ty_transfo_result(
            id             = '001'
            endpointid_sid = '0208'
            endpointid     = '1234567890' ) ).

To make it work, there are 2 solutions:

  1. either you simply omit skip by making use of tt:extensible="deep-dynamic" (among other possible values)
  2. or you use a dummy namespace prefix as shown below (use whatever prefix name you want)

Solution 1 with tt:extensible="deep-dynamic":

    TYPES: BEGIN OF ty_transfo_result,
             id             TYPE string,
             endpointid_sid TYPE string,
             endpointid     TYPE string,
           END OF ty_transfo_result.
    transfo_name = create_transfo( concat_lines_of( sep = |\r\n| table = VALUE string_table(
              ( `<?sap.transform simple?>                                                        ` )
              ( `<tt:transform                                                                   ` )
              ( `xmlns:tt="http://www.sap.com/transformation-templates"                          ` )
              ( `xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2"` )
              ( `xmlns:ddic="http://www.sap.com/abapxml/types/dictionary"                        ` )
              ( `xmlns:def="http://www.sap.com/abapxml/types/defined">                           ` )
              ( `  <tt:root name="INVOICE"/>                                                     ` )
              ( `                                                                                ` )
              ( `  <tt:template>                                                                 ` )
              ( `    <Invoice xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2"     ` )
              ( `        tt:extensible="deep-dynamic">                                           ` )
              ( `      <ID tt:value-ref="INVOICE.ID"/>                                           ` )
              ( `      <EndpointID>                                                              ` )
              ( `        <tt:attribute name="schemeID" value-ref="INVOICE.ENDPOINTID_SID"/>      ` )
              ( `        <tt:value ref="INVOICE.ENDPOINTID"/>                                    ` )
              ( `      </EndpointID>                                                             ` )
              ( `    </Invoice>                                                                  ` )
              ( `  </tt:template>                                                                ` )
              ( `                                                                                ` )
              ( `</tt:transform>                                                                 ` ) ) ) ).
    DATA(transfo_result) = VALUE ty_transfo_result( ).
    DATA(xml) ='<Invoice xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2">'
            && '  <Bob1>Blablabla</Bob1>                                                '
            && '  <ID>001</ID>                                                          '
            && '  <EndpointID schemeID="0208">1234567890</EndpointID>                   '
            && '  <Bob2>450</Bob2>                                                      '
            && '</Invoice>                                                              '.
    CALL TRANSFORMATION (transfo_name)
        SOURCE XML xml
        RESULT invoice = transfo_result.
    cl_abap_unit_assert=>assert_equals(
        act = transfo_result
        exp = VALUE ty_transfo_result(
            id             = '001'
            endpointid_sid = '0208'
            endpointid     = '1234567890' ) ).


Solution 2 with dummy namespace prefix:

    TYPES: BEGIN OF ty_transfo_result,
             id             TYPE string,
             endpointid_sid TYPE string,
             endpointid     TYPE string,
           END OF ty_transfo_result.
    transfo_name = create_transfo( concat_lines_of( sep = |\r\n| table = VALUE string_table(
              ( `<?sap.transform simple?>                                                        ` )
              ( `<tt:transform                                                                   ` )
              ( `xmlns:tt="http://www.sap.com/transformation-templates"                          ` )
              ( `xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2"` )
              ( `xmlns:ddic="http://www.sap.com/abapxml/types/dictionary"                        ` )
              ( `xmlns:def="http://www.sap.com/abapxml/types/defined">                           ` )
              ( `  <tt:root name="INVOICE"/>                                                     ` )
              ( `                                                                                ` )
              ( `  <tt:template>                                                                 ` )
              ( `    <Invoice xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2"     ` )
              ( `        xmlns:dummy="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2">   ` )
              ( `      <tt:skip count="1" name="dummy:Bob1"/>                                    ` )
              ( `      <ID tt:value-ref="INVOICE.ID"/>                                           ` )
              ( `      <EndpointID>                                                              ` )
              ( `        <tt:attribute name="schemeID" value-ref="INVOICE.ENDPOINTID_SID"/>      ` )
              ( `        <tt:value ref="INVOICE.ENDPOINTID"/>                                    ` )
              ( `      </EndpointID>                                                             ` )
              ( `      <tt:skip count="1" name="dummy:Bob2"/>                                    ` )
              ( `    </Invoice>                                                                  ` )
              ( `  </tt:template>                                                                ` )
              ( `                                                                                ` )
              ( `</tt:transform>                                                                 ` ) ) ) ).
    DATA(transfo_result) = VALUE ty_transfo_result( ).
    DATA(xml) ='<Invoice xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2">'
            && '  <Bob1>Blablabla</Bob1>                                                '
            && '  <ID>001</ID>                                                          '
            && '  <EndpointID schemeID="0208">1234567890</EndpointID>                   '
            && '  <Bob2>450</Bob2>                                                      '
            && '</Invoice>                                                              '.
    CALL TRANSFORMATION (transfo_name)
        SOURCE XML xml
        RESULT invoice = transfo_result.
    cl_abap_unit_assert=>assert_equals(
        act = transfo_result
        exp = VALUE ty_transfo_result(
            id             = '001'
            endpointid_sid = '0208'
            endpointid     = '1234567890' ) ).

0 Kudos

Hi Sandra,

Thanks for your help !
Indeed the question XML deserialization: error tt:skip and namespaces | SAP Community is very interesting.
The trick with the dummy namespace also.

So in my situation, I just want to read 3 <tags> of a complex XML, I can use tt:extensible on my root <tag> ?

tt:extensible="deep-dynamic"

I think it's probably the best solution in my case.

0 Kudos

Yes.

abo
Active Contributor

sandra.rossi As usual, I go through your examples first trying them on the MiniSAPs, then saving them for reference.

In this case, on A4H (HANA1909) I get an error that "create_transfo" is unknown: is that to be expected?

c5e08e0478aa4727abc4482f5be390b2 It's as expected 😉 I didn't publish the whole test program containing the dynamic creation of the transformation (it could be a new blog post with title "Convenient ST/XSLT test tool for ABAPers"), only the relevant part. To make it work, create the Z transformation the classic way and it will work.