Replaces fragments of an XML string.

ExampleXML Functions (LR_XML)


lr.xmlReplace( {object} );

JavaScript Object

   xmlFragment:"<string>", | xmlFragmentParam:"<string>", 
Property Name
xmlThe XML Input String to query.
resultParamThe name of the output parameter containing the XML data after replacing the new value.
queryThe XML Query on the input string XML.
xmlFragmentThe value to use as replacement of the query match—an element or an attribute.
xmlFragmentParamThe name of the parameter containing the string value to use as replacement.
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.
notFound See Continuing on Error.

The lr.xmlReplace function queries the XML input string XML for values matching the Query criteria and replaces them either with XmlFragment or XmlFragmentParam as the value of the elements matched by the query. You can replace elements by specifying either its element name or attribute in the XML Query. The resulting string 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.

If there is more than one value to be replaced, then pass the "XmlFragmentParam=" specification. Save the values in a series of parameters with the names:

Param_1, Param_2, Param_3, ...

where Param is the value "XmlFragmentParam=Param". lr.xmlReplace replaces each successive match of the Query with the value of the next parameter in the series. For an example of multiple-value query see lr.xmlSetValues.

Return Values

All XML functions return the number of matches successfully found or zero on failure.


Input parameters to XML functions with the following names can be parameterized:

  • XML

  • Query

  • Value

  • XmlFragment


function Action(){

   var xmlInput =
     " <name>John Smith</name>"+
   lr.saveString(xmlInput, "XML_Input_Param");
   lr.xmlReplace({xml:"{XML_Input_Param}", resultParam:"Result", 

       lr.outputMessage(lr.evalString("String after replacement: {Result}"));

return 0;