XML Functions (LR_XML) > Alphabetical List of Functions > lr_xml_insert

lr_xml_insert

Example: lr_xml_insert XML Functions (LR_XML)

Inserts a new XML fragment into an XML string.

int lr_xml_insert( <List of specifications> [, <List of optional specifications> ] [, LAST]);
List of specifications

For the following list of required specifications, use the following string format:"Specification=value"

XML: the XML Input String to query
ResultParam: The output parameter containing the XML data after inserting the new fragment
Query: the XML Query on the input string XML.

Choose one of the following:
XmlFragment: the string to insert. It can be a new element or a attribute of an existing element.
or:
XmlFragmentParam: the name of the parameter containing the string value to insert

List of optional specifications

For the following list of optional specifications, use the following string format:"Specification=value"

SelectAll: If "yes", all elements matching the query will be processed. If "no", only the first match will be processed. Default is "no". See Multiple Query Matching

Position: the position to insert the XML fragment. Choose one of:

  • before: place the fragment before the tag returned by a Query
  • after: place the fragment after the tag returned by a Query (this is the default value)
  • child: place the fragment as a child of the tag returned by a Query
  • attribute: indicates an attribute of an element returned by a Query

NotFound: See Continuing on Error

LAST A marker which indicates the end of the List of optional specifications

The lr_xml_insert function queries the XML input string XML for values matching the Query criteria. It then inserts XmlFragment or XmlFragmentParam at the position (or positions) in the XML string returned by the Query.

Position specifies whether the insertion is done before or after the point returned. Additionally, the childPosition specifies that the fragment is inserted before the end of the tag found by the query. For example, if the input string is

<a>53</a>

an inserted fragment ("<b>ZZ</b>") in the child position will result in the string:

<a>53<b>ZZ</b></a>

The resulting string after insertion is placed in ResultParam, using the source document encoding. The output preserves the XML Character Encoding of the original document, independent of the input encoding. The input encoding uses the client's local encoding.

Return Values

See Return Values

Parameterization

See Parameterization