Example: lr_xml_insert

The following example inserts an "extension" tag to an employee record. It searches the input string xml_input for the tag "<employee>" and inserts an XML fragment which contains the extension information. ("XmlFragment=<extension>2145</extension>").

Note that the Position specification is child, so the inserted string fragment is placed just before the employee tag ends (at "</employee>").

The resulting string is contained in the ResultParam parameter, Result.

For more examples of the use of lr_xml_insert, see the sections Insert an attribute to the root and Insert a child in all elements using a parameter in Example Scripts for XML Queries.

#include "as_web.h"

char *xml_input =
          " <name>John Smith</name>"

Action() {

     lr_save_string(xml_input, "XML_Input_Param");

     lr_xml_insert("XML={XML_Input_Param}", "ResultParam=Result",
          "Position=child", LAST );

     lr_output_message(lr_eval_string("String after insertion: {Result}"));

     return 0;

Example: Output:
Action.c(15): "lr_xml_insert" was successful, 1 match processed
Action.c(20): String after insertion:
<acme_org><employee> <name>John Smith</name>