2019 Nov 29 11:31 AM
I use ST to create an XML file from ABAP. The transformation works finde except for one tiny, yet crucial part.
Here's what the XML should look like in the end:
<?xml version="1.0" encoding="utf-8"?>
<Paket>
<Metadaten>
<DOKNR>N1-QCPRT-000231</DOKNR><DOKAR>DOC</DOKAR><DOKVR>-</DOKVR><DOKTL>000</DOKTL><WFRelevant>J</WFRelevant>
</Metadaten>
</Paket>
The tags in line 4 have dynamic names, depending on the metadata parameters read by the program. Since ST is not built for handling such dynamic stuff, I create this line manually in ABAP by writing it into a string variable (PAKET.METADATEN) and use it in my transformation:
<?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">
<tt:root name="ROOT" type="?"/>
<tt:root name="PAKET" type="ddic:ZPD_S_XML_PAKET_ROOT"/>
<tt:template>
<Paket>
<tt:serialize>
<Metadaten><tt:value ref=".PAKET.METADATEN"/></Metadaten>
</tt:serialize>
</Paket>
</tt:template>
</tt:transform>
I transform it writing the output into an xstring variable (to get an UTF-8 XML). The transformation now interprets the angle brackets in the string as '& lt;' for '<' and '& gt;' for '>' (ignore the whitespace ;-)) which leads to the following output XML (in bytes, since this editor here is able to interpret it correctly:
3c3f786d6c2076657273696f6e3d22312e302220656e636f64696e673d227574662d38223f3e0a3c50616b65743e0a093c4d657461646174656e3e266c743b444f4b4e522667743b4e312d51435052542d303030323331266c743b2f444f4b4e522667743b266c743b444f4b41522667743b444f43266c743b2f444f4b41522667743b266c743b444f4b56522667743b2d266c743b2f444f4b56522667743b266c743b444f4b544c2667743b303030266c743b2f444f4b544c2667743b3c2f4d657461646174656e3e0a3c2f50616b65743e<br>
I'm working on a unicode system and thus the string value is represented in unicode. The output must be a UTF-8 xml file.
So the basic question is: How can I either realize such dynamic tag names without filling a string variable or have ST interpret the string properly, so that the angle brackets are shown in the output?
2019 Nov 29 12:36 PM
Check out XML Fragments.
Demo program for ST = DEMO_ST_XSDANY - method prepare_fragment is creating XML string which is later inserted in transformation to result XML.
By the way XML Fragments works in XSL Transformation too (not only in Simple Transformations).
2019 Nov 29 12:36 PM
Check out XML Fragments.
Demo program for ST = DEMO_ST_XSDANY - method prepare_fragment is creating XML string which is later inserted in transformation to result XML.
By the way XML Fragments works in XSL Transformation too (not only in Simple Transformations).
2019 Dec 03 9:57 AM
Hi Tomas,
thanks a lot for this hint. This solved the initial problem of broken tags 🙂 However, < and > within such nodes (e.g. arrow symbols in description texts) are still translated into & lt ; and & gt ; (without whitespace) . Do you know why this happens?
Best
Patrick
2019 Dec 03 10:05 AM
patricksteffens It looks like you need to escape the values in your XML string (fragment) before transformation.
For example you have a value "two > one" in tag <value>. After escaping the complete string would look like - EDIT: without spaces after ampresand, sap.com forum is unescaping escaped value > 😞
<value>two & gt ; one</value>
2019 Dec 03 11:26 AM
I replaced all < by & lt ; and all > by & gt ; (without whitespace) before the id transformation.
In the output XML, they are not translated back into < and >.Even worse: The & is interpreted as & amp ; which makes somewhat sense to me.
Or did I get you wrong?
2019 Dec 03 12:10 PM
Patrick Steffens Why is it a problem that a text with character > is seritalized into & gt; ? (by the way it's not related to the question which was about including an XML fragment in an XML element) That's how XML works: the deserialization will interpret & gt; as the character >. Same thing for & which is serialized into & amp;. Do you have an example to describe your problem? Or is it just because you don't "like" it?
2020 Jan 06 4:24 PM
sandra.rossi : We encountered problems where description texts are not translated consistently. E.g. the text "ä<" would be translated into "ä& lt ;" (without whitespace) which is a problem for our software parsing the XML (it fails reading the 'ä' symbol). Thus I would like to have either all or no symbol transformed. So either I would expect all symbols to be translated or none.
Is there an explanation for this observation?
2020 Jan 06 4:26 PM
By the way, I tried to escape the tag containing these symbols via CDATA but this did not have an effect.