首页 > 代码库 > LoadRunner 函数之lr_xml_get_values

LoadRunner 函数之lr_xml_get_values

技术分享

简单实例如

char *xml_input =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
"<S:Envelope xmlns:S=\"http://schemas.xmlsoap.org/soap/envelope/\">"
  "<S:Body>"
    "<ns2:handleResponse xmlns:ns2=\"http://eaop.gd.chinamobile.com/\">"
      "<return>"
        "<queryecouponsbymobilenumresp>"
          "<msgheader>"
            "<req_seq>20161206165439111</req_seq>"
            "<ope_seq>20161220161336177143</ope_seq>"
            "<retinfo>"
              "<rettype>0</rettype>"
              "<retcode>0</retcode>"
              "<retmsg>success</retmsg>"
            "</retinfo>"
          "</msgheader>"
		  "<msgbody>"
		  "</msgbody>"
        "</queryecouponsbymobilenumresp>"
      "</return>"
    "</ns2:handleResponse>"
  "</S:Body>"
"</S:Envelope>";

Action(){
	lr_save_string(xml_input, "XML_Input_Param"); // Save input as parameter
	// lr_xml_get_values:Retrieves values of XML elements found by a query. 
    lr_xml_get_values("XML={XML_Input_Param}",
          "ValueParam=OutputParam",
          "Query=/Envelope/Body/handleResponse/return/queryecouponsbymobilenumresp/msgheader/retinfo/retcode",
          LAST );
    lr_output_message(lr_eval_string("Query result = {OutputParam}"));
	return 0;
}

输入结果如

技术分享

 

LoadRunner 函数之lr_xml_get_values