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 =
"<acme_org>"
"<employee>"
" <name>John Smith</name>"
"<cubicle>227</cubicle>"
"</employee>"
"</acme_org>";
Action() {
lr_save_string(xml_input, "XML_Input_Param");
lr_xml_insert("XML={XML_Input_Param}", "ResultParam=Result",
"XmlFragment=<extension>2145</extension>",
"Query=/acme_org/employee",
"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>
<cubicle>227</cubicle><extension>2145</extension>
</employee></acme_org>