lr.xmlFind

Verifies that XML values are returned by a query.

ExampleXML Functions (LR_XML)

Syntax

lr.xmlFind( {object} );

JavaScript Object

{
   xml:"<string>",
   query:"<string>", | fastQuery:"<string>",
   value:"<string>", | valueParam:"<string>",
   selectAll:"<string>",
   ignoreCase:"<string>",
   useRegExp:"<string>",
   notFound:"<string>"
} 
Property Name
Description
xmlThe XML Input String to query
queryThe XML Query on the input string xml.
fastQueryThe Fast Query on the input string xml.
valueThe string to find. This can be the element value or its attribute value.
valueParamThe parameter name containing the string to find.
selectAllIf "yes", all elements matching the query will be processed. If "no", only the first query match will be verified. Default is "no". See Multiple Query Matching.
ignoreCaseIf "yes", the search will ignore the difference between uppercase and lowercase characters of value or valueParam and query results. Default is "no".
useRegExpIf "yes", value or valueParam can be regular expressions that the function will search for. For more information, see Regular Expressions. The default is "UseRegExp=no".
notFoundSee Continuing on Error

The lr.xmlFind function queries the XML input string XML for values matching the Query criteria (Value or ValueParam) and returns the number of occurrences. If SelectAll is "no", lr.xmlFind returns either 1 or 0.

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>"+
       "<employee level=\"manager\">John Smith"+
       "<cubicle>227</cubicle>"+
       "</employee>"+
       "</acme_org>";

   var find_cnt;

       lr.saveString(xmlInput, "XML_Input_Param");

       /* Verify that employee John Smith exists */
       find_cnt = lr.xmlFind({xml:'{XML_Input_Param}',
        value : "John Smith", 
        query: "/acme_org/employee" });

       if (find_cnt >0)
   {
       /* Insert John Smith's telephone extension number */
       lr.xmlInsert({xml:"{XML_Input_Param}",
            resultParam :"Result",
            xmlFragment: "<extension>2145</extension>", 
            query :"/acme_org/employee",
            position: "child"} 
        );

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

       } // end if find_cnt > 0

return 0;
}

See also: Example: lr.xmlFind