Share this page

# lr.xmlSetValues

Sets the values of XML elements found by a query.

JavaScript XML Functions (lr.xml)

## Syntax

    lr.xmlSetValues( {object} );

## JavaScript Object

    {
       xml:"<string>",
       resultParam:"<string>",
       query:"<string>",
       value:"<string>", | valueParam:"<string>",
       selectAll:"<string>",
       notFound:"<string>"
    }

Property Name | Description
--- | ---
xml | The XML Input String to query.
resultParam | The name of the output parameter containing the XML data after replacing the new value.
query | The XML Query on the input string XML.
value | The value to set as the XML element.
valueParam | The name of the parameter containing the value to set as the XML element.
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.xmlSetValues function queries the XML input string XML for values matching the Query criteria and sets either Value or ValueParam as the value of the elements matched by the query.

The XML input string can be a literal string containing XML data. For example:

"XML=<employee>John Smith</employee>

Alternatively, the XML string can be a parameter containing the XML data. For example:

"XML={EmployeeNameParam}"

You can pass the input value required as a string ("Value=string"), or as a parameter which contains the string ("ValueParam={Param}").

If there is more than one value to be replaced, then use ValueParam. Save the values in a series of parameters with the names:

Param_1, Param_2, Param_3, ...

where Param is the value "ValueParam=Param". lr.xmlSetValues sets each successive match of the Query to the value of the next parameter in the series.

When parameters with the names ValueParam or ResultParam already exist, their value is overwritten. ResultParam is returned 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.

For information and examples about Query see XML Query.

## Return Values

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

## Parameterization

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

- XML

- Query

- Value

- XmlFragment

## Example

    function Action(){

       var xmlInput =
          "<acme_org>"+
          "<accounts_dept>"+
          "<employee>"+
          "<name>John Smith</name>"+
          "<cubicle>227</cubicle>"+
          "<extension>2145</extension>"+
          "</employee>"+
          "</accounts_dept>"+
          "<engineering_dept>"+
          "<employee>"+
          "<name>Sue Jones</name>"+
          "<extension>2375</extension>"+
          "</employee>"+
          "</engineering_dept>"+
          "</acme_org>";

           var i, numOfValues;

           lr.saveString(xmlInput, "XML_Input_Param"); // Save input as parameter
           lr.saveString("1111", "ExtensionParam_1");
           lr.saveString("2222", "ExtensionParam_2");

           lr.xmlSetValues({xml:"{XML_Input_Param}",
               resultParam:"NewXmlParam",
               valueParam:"ExtensionParam",
               selectAll:"yes",
               query:"//extension"
           });

           numOfValues= lr.xmlGetValues({xml:"{NewXmlParam}",
              valueParam:"OutputParam",
              query:"//extension",
              selectAll:"yes"});

           for ( i = 0; i < numOfValues; i++) { /* Print the multiple values of MultiParam */
               var buf = "Retrieved value "+ (i+1) +" : {OutputParam_}" + (i+1);

               lr.outputMessage(lr.evalString(buf));
           }

    return 0;
    }

Tips to improve your search results... VuGen Function Reference Version 26.1-26.3 Function Reference 26.1-26.3 All View Local Help Center View Online Help Center Version: