Example: lr_xml_replace
The following example changes the telephone extension number of an employee from 2145 to 4444. It searches the input string xml_input for the tag "<extension>" and replaces the tag with an XML fragment containing the number 4444 ("XmlFragment=<extension>4444</extension>"). The resulting string is contained in the ResultParam parameter, Result.
For more examples of the use of lr_xml_replace, see Replacing and inserting elements in Example Scripts for XML Queries.
#include "as_web.h"
char *xml_input =
"<acme_org>"
"<employee>"
" <name>John Smith</name>"
"<cubicle>227</cubicle>"
"<extension>2145</extension>"
"</employee>"
"</acme_org>";
Action() {
lr_save_string(xml_input, "XML_Input_Param");
lr_xml_replace("XML={XML_Input_Param}", "ResultParam=Result",
"Query=/acme_org/employee/extension",
"XmlFragment=<extension>4444</extension>", LAST );
lr_output_message(lr_eval_string("String after replacement: {Result}"));
return 0;
}
Example: Output:
Action.c(20): String after replacement: <acme_org><employee> <name>John Smith</name><cubicle>227</cubicle> <extension>4444</extension></employee></acme_org>