Show TOC

Syntax documentationLiteral XML Elements and Attributes Locate this document in the navigation structure

Use

Literal XML elements are XML elements that are not ST commands or that do not lie within the namespace http://www.sap.com/transformation-templates (namespace prefix tt). Attributes of literal XML elements that do not lie within this namespace are called literal attributes.

During serialization, literal XML elements and their literal attributes are passed to the target XML document unchanged; during deserialization they are compared with the XML source document word by word. Besides 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

General literal XML elements have the following syntax:

Syntax Syntax

  1. <element [attr] [tt:ref=″node″>]
  2.                 [tt:lax=lax_flag]
  3.                 [tt:extensible=extensible_flag]>
  4.   ...
  5. </element>
End of the code.

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 tt:extensible only have an effect with deserialization. tt:lax determines whether the element name element may differ during deserialization. tt:extensible specifies whether the element’s content can be extended by unspecified elements.

Serializing Literal XML Elements

During serialization, the element beginning <element [attr]>, together with its literal attributes attr, is passed to the target XML document, the content of the element is serialized, and then the element ending </element> is passed. If there are multiple literal attributes with the same name, only the last one is passed.

Note Note

For information about handling namespaces, see Namespaces.

End of the note.
Deserializing Literal XML Elements

During deserialization, the beginning of the element is compared to the current position of the source XML document. By default, the source XML document must contain an element with the same name 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 literal attributes with the same name, only the last one is considered.

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 attributes combines the tt:value command with the above syntax:

Syntax Syntax

  1. <element [attr] tt:value-ref=″node″ 
  2.                 [tt:lax=lax_flag]
  3.                 [tt:map=″mapping_list″] 
  4.                 [tt:length|tt:minLength|tt:maxLength=″length″] />
End of the code.

This special form is a short form of:

Syntax Syntax

  1. <element [attr] [tt:lax=lax_flag]>
  2.   <tt:value ref=″node″ [map=″mapping_list″] 
  3.                        [length|minLength|maxLength=″length″] />
  4. </element>
End of the code.

This allows you to easily formulate the frequent occurring situation when you need to express an elementary value as the content of an XML element.

Attribute tt:extension cannot be specified together with tt:value-ref.

Example

The following ST program can be used to serialize an elementary data object:

Syntax Syntax

  1. <tt:transform xmlns:tt="http://www.sap.com/transformation-templates">
  2.   <tt:root name="ROOT"/>
  3.   <tt:template>
  4.      <X my_attr="attr">
  5.        <tt:value ref="ROOT" />
  6.      </X>
  7.   </tt:template>
  8. </tt:transform>
End of the code.

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>

Note that literal text that does not contain anything but blank space (blanks and line breaks) is irrelevant in ST programs by default. For this reason, the serialization does not result in:

Syntax Syntax

  1. <X my_attr="attr">
  2.    abc
  3. </X>
End of the code.

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 can deserialize the result, whereby the literal attribute my_attr is ignored:

Syntax Syntax

  1. <tt:transform xmlns:tt="http://www.sap.com/transformation-templates">
  2.   <tt:root name="ROOT"/>
  3.   <tt:template>
  4.     <X>
  5.       <tt:value ref="ROOT"/>
  6.     </X>
  7.   </tt:template>
  8. </tt:transform>
End of the code.

The following ST program shows the short form identical to the program above:

Syntax Syntax

  1. <tt:transform xmlns:tt="http://www.sap.com/transformation-templates">
  2.   <tt:root name="ROOT"/>
  3.   <tt:template>
  4.     <X tt:value-ref="ROOT" />
  5.   </tt:template>
  6. </tt:transform>
End of the code.

The following ST program triggers the exception CX_ST_MATCH_ELEMENT, because an element X is passed instead of element Y.

Syntax Syntax

  1. <tt:transform xmlns:tt="http://www.sap.com/transformation-templates">
  2.   <tt:root name="ROOT"/>
  3.   <tt:template>
  4.     <Y>
  5.       <tt:value ref="ROOT"/>
  6.     </Y>
  7.   </tt:template>
  8. </tt:transform>
End of the code.

The following ST program triggers the exception CX_ST_MATCH_ATTRIBUTE even though the element names match, because the expected literal attribute my_value does not exist in the source document.

Syntax Syntax

  1. <tt:transform xmlns:tt="http://www.sap.com/transformation-templates">
  2.   <tt:root name="ROOT"/>
  3.   <tt:template>
  4.     <X my_value="value">
  5.       <tt:value ref="ROOT"/>
  6.     </X>
  7.   </tt:template>
  8. </tt:transform>
End of the code.

A correct attribute name with an incorrect attribute content triggers the exception CX_ST_MATCH_TEXT.