JavaScript Functions > Alphabetical Listing of Utility Functions (lr) > lr.xmlFind

lr.xmlFind

Verifies that XML values are returned by a query.

Example XML 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
xml The XML Input String to query
query The XML Query on the input string xml.
fastQuery The Fast Query on the input string xml.
value The string to find. This can be the element value or its attribute value.
valueParam The parameter name containing the string to find.
selectAll If "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.
ignoreCase If "yes", the search will ignore the difference between uppercase and lowercase characters of value or valueParam and query results. Default is "no".
useRegExp If "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".
notFound See 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:

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