Get Example source ABAP code based on a different SAP table
ABAP_ASXML - Mapping of XML Fragments This example demonstrates the mapping of XML fragments.
ABAP_SOURCE_CODE DEMO CL_DEMO_ASXML_FRAGMENT
ABAP_DESCRIPTION This example demonstrates the serialization and deserialization of XML fragments and their representation in asXML using the identity transformation> ID>.
First, an XML fragment with the root element X> is created in a variable xstr> with the type xstring> and the result is displayed.
The fragment is serialized from the variable xstr> of type xstring> to an element ROOT> as the XML schema type xsd:base64Binary> in accordance with the rules for the mapping of elementary data types>.
On the other hand, a serialization of the fragment from the variable xsdstr> of type XSDANY> adds the attribute asx:root> with the content X>, that is, the name of the root element of the XML fragment) to the element ROOT> and represents the remaining content of the fragment in an unchanged way.
A further serialization of the fragment from the variable xsdstr> produces the element X>. This has the same name as the root element of the XML fragment and so the attribute is not added.
Any attempt to deserialize the fragment content to an ABAP variable of type xstring> fails for both serialization results, since the attribute specified for NODE> when mapping elementary data types is not supported or because no valid asXML format exists for the target variable.
Deserializations to variables of type XSDANY> are possible in both cases, however, and create the original XML fragment again in the variable.
If a nonexistent element is addressed in deserializations, no deserialization is performed as usual. For information about serializations and deserializations of XML fragments using Simple Transformations>, see the executable example ST, Mapping of XML Fragments >.