2015 Jan 27 8:36 PM
I am currently trying to do a simple transformation in STRANS that will require the prefix <x:> for all my tags. I have added a namespace entry in STRANS of xmlns:x="http://www.w3.org/2001/XMLSchema" and labeled my element "x.PLANT".
My SourceCde looks like this:
<?sap.transform simple?>
<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"
xmlns:x="http://www.w3.org/2001/XMLSchema">
<tt:root name="PLANT" type="ddic:WERKS_D"/>
<tt:template>
<x:PLANT tt:value-ref=".PLANT"/>
</tt:template>
</tt:transform>
My XML file looks like this:
<?xml version="1.0" encoding="UTF-8" ?>
<x:PLANT>1201</x:PLANT>
When I run call my transformation:
| DATA: gt_itab | TYPE STANDARD TABLE OF char2048. |
data : result type werks_d,
wa_result type werks_d. |
| call transformation Z_TEST | |
| SOURCE XML gt_itab |
| result | plant = result. |
I get a short dump stating the following:
Error analysis
An exception occurred 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-start: "PLANT" [http://www.w3.org/2001/XMLSchema] Read was
invalid: " " [ ].
Can someone please offer a solution to the pain I am currently experiencing? All thoughts are much appreciated.
I am currently trying to do a simple transformation in STRANS that will require the prefix <x:> for all my tags. I have added a namespace entry in STRANS of xmlns:x="http://www.w3.org/2001/XMLSchema" and labeled my element "x.PLANT".
My SourceCde looks like this:
<?sap.transform simple?>
<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"
xmlns:x="http://www.w3.org/2001/XMLSchema">
<tt:root name="PLANT" type="ddic:WERKS_D"/>
<tt:template>
<x:PLANT tt:value-ref=".PLANT"/>
</tt:template>
</tt:transform>
My XML file looks like this:
<?xml version="1.0" encoding="UTF-8" ?>
<x:PLANT>1201</x:PLANT>
When I run call my transformation:
| DATA: gt_itab | TYPE STANDARD TABLE OF char2048. |
data : result type werks_d,
wa_result type werks_d. |
| call transformation Z_TEST | |
| SOURCE XML gt_itab |
| result | plant = result. |
I get a short dump stating the following:
Error analysis
An exception occurred 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-start: "PLANT" [http://www.w3.org/2001/XMLSchema] Read was
invalid: " " [ ].
Can someone please offer a solution to the pain I am currently experiencing? All thoughts are much appreciated.
2015 Jan 28 9:49 AM
You have specified the namespace in transformation but the source xml does not have that detail.
If I include the namespace in source xml, the code works.
<?xml version="1.0" encoding="UTF-8" ?>
<x:PLANT xmlns:x="http://www.w3.org/2001/XMLSchema">1201</x:PLANT>
2015 Jan 28 2:35 PM
Manish,
I tried your solution and still received the Short Dump as before.
XML matching error
Expected was element-start: "PLANT" [http://www.w3.org/2001/XMLSchema] Read was
invalid: " " [ ].
In my eventual Simple Transformation, I will be attempting to read an XML file that will contain a Namespace (ex. "x." for several hundred elements) in every element sent. I have no expectation that I will alter the XML file, thus I was hoping the solution would be in SAP. Thanks for your response.
Regards,
Bill
2015 Jan 28 2:50 PM
It did work for me with modified xml, your code and your STRANS code.
Now I remember, there was one more thing that I changed.
SOURCE XML gt_itab was changed to SOURCE XML lv_string
lv_string is type string and has entire xml.
I have always passed xml as a single variable of string type, not as internal table.
As for larger xml, specifying the namespace in just the root element is enough. The child elements would simply inherit the namespace.
If xml is improper, it needs to be modified before passing to STRANS.
If you paste your xml in XML Validator, the validation will fail.
Note: You can avoid the dumps by catching the exceptions using try..catch..endtry block.
2015 Jan 28 3:19 PM
Here, try this code and call your transformation.
DATA result TYPE werks_d.
DATA lv_xml TYPE string.
CONCATENATE
'<?xml version="1.0" encoding="UTF-8" ?>'
'<x:PLANT xmlns:x="http://www.w3.org/2001/XMLSchema">1201</x:PLANT>'
INTO lv_xml.
CALL TRANSFORMATION zm1
SOURCE XML lv_xml
RESULT plant = result.
WRITE result.
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |