ALERT! The community will be read-only starting on April 19, 8am Pacific as the migration begins. Read more for important details.
ALERT! The community will be read-only starting on April 19, 8am Pacific as the migration begins.Read more for important details.
Lieutenant Commander
Lieutenant Commander
4473 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
Fleet Admiral
Fleet Admiral

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
Fleet Admiral
Fleet Admiral

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
Lieutenant Commander
Lieutenant Commander

Hi 

0 Likes
Fleet Admiral
Fleet Admiral

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

Captain
Captain

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

Lieutenant Commander
Lieutenant Commander

Hi Ola Berggren,

Many thanks!

Regards,

Sachin

0 Likes
Lieutenant Commander
Lieutenant Commander

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.