SAP ST XML LITERALS



Get Example source ABAP code based on a different SAP table
  



ABAP_ST - Literal XML Elements and Attributes
Literal XML elements are XML elements that are not ST statements or that are not in the namespace http://www.sap.com/transformation-templates (namespace prefix tt). Attributes of literal XML elements that are not in this namespace are called literal attributes.
During serialization, literal XML elements and their literal attributes are passed to the target XML document unchanged. In deserializations they are compared with the XML source document word by word. In addition to the literal attributes, literal XML elements can also contain certain attributes with the namespace prefix tt, that is, ST-specific attributes, to set the current node and to control behavior during deserialization.

General Literal XML Elements

ABAP_SYNTAX
< element $[attr$] $[tt:ref='node'>$]
$[tt:lax=...$]
$[tt:extensible=...$]>
...
< /element>

What does it do?
Here, element is the name of the element and attr is a set of optional literal attributes with any name. The optional ST-specific attribute tt:ref sets the current node node for the context of the literal element.
The optional ST-specific attributes tt:lax and tt:extensible only have an effect during deserialization. tt:lax determines whether the element name element may differ during deserialization. tt:extensible specifies whether the content of the element can be extended by unspecified elements.

Serializing Literal XML Elements
In serializations, the element beginning < element $[attr$]> and its literal attributes attr are passed to the target XML data, the content of the element is serialized, and then the element ending < /element> is passed. If there are multiple identically named literal attributes, only the last one is passed.



Latest notes:

For information about handling namespaces, see tt.namespace, Namespaces.
NON_V5_HINTS
ABAP_HINT_END

Deserializing Literal XML Elements
In deserializations, the beginning of the element is compared with the current position of the outbound XML data. By default, the source XML data must contain an identically named element with all literal attributes attr of the same content. The order of the literal attributes is of no importance. Superfluous literal attributes of the element in the source document are always ignored. If there are multiple identically named literal attributes, only the last one is respected.
After a successful comparison of the element beginning, the element content is deserialized and then the element ending is consumed.

Special Form of Literal XML Elements
A special form of literal XML attributes combines the tt:value statement with the above syntax.

ABAP_SYNTAX
< element $[attr$] tt:value-ref='node'
$[tt:lax=...$]
$[tt:map=...$]
$[tt:length$|tt:minLength$|tt:maxLength='len'$] />
This special form is a short form of:
< element $[attr$] $[tt:lax=...$]>
< tt:value ref='node' $[map=...$]
$[length$|minLength$|maxLength='len'$] />
< /element>
This makes it easy to formulate the frequent use case of expressing an elementary value as the content of an XML element.
The attribute tt:extensible cannot be specified together with tt:value-ref.

ABAP_EXAMPLE_VX5
The following ST program DEMO_ST_XML_LITERALS1 can be used to serialize an elementary data object:
TRNS DEMO_ST_XML_LITERALS1
The result of a serialization is as follows if abc is the value of the ABAP data object bound to ROOT. < X my_attr='attr'>abc < /X>
It should be noted that literal text that contains nothing but blank spaces (blanks and line breaks) is irrelevant in ST programs by default. For this reason, the serialization does not produce the following, for example: < X my_attr='attr'>
abc
< /X>
If the results of serializations with indents and line breaks are shown in examples, they are usually used for clarification and are not actually part of the result.
The following ST program DEMO_ST_XML_LITERALS2 can deserialize the result, whereby the literal attribute my_attr is ignored:
TRNS DEMO_ST_XML_LITERALS2
The following ST program DEMO_ST_XML_LITERALS3 shows the equivalent short form to the program above:
TRNS DEMO_ST_XML_LITERALS3
The following ST program DEMO_ST_XML_LITERALS4 raises the exception CX_ST_MATCH_ELEMENT , because an element X is returned instead of element Y .
TRNS DEMO_ST_XML_LITERALS4
The following ST program DEMO_ST_XML_LITERALS5 raises the exception CX_ST_MATCH_ATTRIBUTE despite identical element names because the expected literal attribute my_value does not exist in the source document.
TRNS DEMO_ST_XML_LITERALS5
A correct attribute name with an incorrect attribute content raises the exception CX_ST_MATCH_TEXT.
ABAP_EXAMPLE_END