Highlighted
Valued Contributor.
Valued Contributor.
3867 views

Query in lr_xml_get_values() function

Jump to solution

Hi All,

I used Web Service Protocol in my script and added the XML script before Action(). Following is my script:

#include "as_web.h"

char *xml_input=
"<MySchool>"
    "<teacher>"
        "<name>"
          "<firstname>MyTeacher</firstname>"
          "<lastname>Gauda</lastname>"
        "</name>"
        "<address>"
          "<street>101 South Street</street>"
          "<city>Dehradun</city>"
          "<email>saranya.rajaram@abc.com</email>"
          "<phone>8015499</phone>"
        "</address>"
    "</teacher>"
     "<student>"
        "<name>"
          "<firstname>Tinku</firstname>"
          "<lastname>Raja</lastname>"
        "</name>"
        "<address>"
          "<street>102 North Street</street>"
          "<city> Bangalore </city>"
          "<email>tinku.raja@xyz.com</email>"
          "<phone>8015498</phone>"
        "</address>"
    "</student>"
"</MySchool>";

Action()

{

/* Query 3: Find the city name of the person whose phone number is 8015498 */
    
    lr_xml_get_values("XML={XML_Input_Param}",

        "ValueParam=Result",
    
       "Query=/MySchool/*/address[phone=\"8015498\"]/city",
       
        LAST );
        
        lr_output_message("City of the person having phone number 8015498: %s", lr_eval_string("{Result}"));
  

* In the above, since city is at the same level as phone, so it worked.

 

/* Query 2: Find the firstname of the person whose phone number is 8015498 */
 
   lr_xml_get_values("XML={XML_Input_Param}",

        "ValueParam=Result",
    
       "Query=/MySchool/*/address[phone=\"8015498\"]/?",
       
        LAST );
        
        lr_output_message("First name of person having phone number 8015498: %s", lr_eval_string("{Result}")); 

return 0;

}

*In the above, since the firstname is not at the same level as phone, I tried some path but it did not work.

By what string should I replace ? to get the firstname of the person whose phone number is 8015498 ?

Best,

Sachin   

0 Likes
1 Solution

Accepted Solutions
Highlighted
Acclaimed Contributor.
Acclaimed Contributor.

Re: Query in lr_xml_get_values() function

Jump to solution

Hi

You can use levels in the search queries also and should think of the [ ] as having.

In your example this would mean

"Query=/MySchool/student[address/phone=\"8015498\"]/name/firstname",

or explained -  student having adress with phone 8015498

br /ola


Please mark post as solved if your problems or questions is/are resolved.
If this post was valuable to you, please consider kudo it.

 

 

.

View solution in original post

6 Replies
Highlighted
Acclaimed Contributor.
Acclaimed Contributor.

Re: Query in lr_xml_get_values() function

Jump to solution

Hi

This looks to much like a schoolassgniment to give the right answer directly.  🙂

Also it is nothing related to LoadRunner or it's implementation, just about creating an xpath that gets you the correct data

So look for a xpath-tutorial like http://www.w3schools.com/xml/xpath_intro.asp or similar. Will help you a lot more than to  provide the answer.

br /ola


Please mark post as solved if your problems or questions is/are resolved.
If this post was valuable to you, please consider kudo it.

.
0 Likes
Highlighted
Valued Contributor.
Valued Contributor.

Re: Query in lr_xml_get_values() function

Jump to solution

Hi 

0 Likes
Highlighted
Acclaimed Contributor.
Acclaimed Contributor.

Re: Query in lr_xml_get_values() function

Jump to solution

Hi

You can use levels in the search queries also and should think of the [ ] as having.

In your example this would mean

"Query=/MySchool/student[address/phone=\"8015498\"]/name/firstname",

or explained -  student having adress with phone 8015498

br /ola


Please mark post as solved if your problems or questions is/are resolved.
If this post was valuable to you, please consider kudo it.

 

 

.

View solution in original post

Highlighted
Super Contributor.
Super Contributor.

Re: Query in lr_xml_get_values() function

Jump to solution

Hi Joshi,

below Quary is working for both the cases, i.e student and teacher

"Query=/MySchool/*[address/phone=\"8015499\"]/name/firstname",

 

Thanks,

Ravi Kumar

Highlighted
Valued Contributor.
Valued Contributor.

Re: Query in lr_xml_get_values() function

Jump to solution

Hi Ola Berggren,

Many thanks!

Regards,

Sachin

0 Likes
Highlighted
Valued Contributor.
Valued Contributor.

Re: Query in lr_xml_get_values() function

Jump to solution

Hi Ravi,

Many thanks!

Regards,

Sachin

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.