LoadRunner 12.55无法转换'字符串'到'字符串'执行xpath字符串函数时出错

时间:2017-10-09 07:48:32

标签: xml xpath loadrunner

我有这个XML:

<root xmlns:foo="http://www.foo.org/" xmlns:bar="http://www.bar.org">
    <actors>
        <actor id="1">Christian Bale</actor>
        <actor id="2">Liam Neeson</actor>
        <actor id="3">Michael Caine</actor>
    </actors>
    <foo:singers>
        <foo:singer id="4">Tom Waits</foo:singer>
        <foo:singer id="5">B.B. King</foo:singer>
        <foo:singer id="6">Ray Charles</foo:singer>
    </foo:singers>
</root>

我希望使用此xpath获取id值:

string(//actor[1]/@id)

我尝试使用lr_xml_find执行xpath查询

lr_xml_find(
    "XML={XML_response}",
    "Query=string(//actor[1]/@id)",
    "Value=1",
    LAST
);

并收到错误:

  

无法转换&#39;字符串&#39;到&#39;字符串&#39;

我的错误在哪儿?

1 个答案:

答案 0 :(得分:0)

您使用的是错误的API调用。您需要使用lr_xml_extract

示例:

#include "as_web.h"

char *xml_input = 
"<root xmlns:foo=\"http://www.foo.org/\" xmlns:bar=\"http://www.bar.org\">"
    "<actors>"
        "<actor id=\"1\">Christian Bale</actor>"
        "<actor id=\"2\">Liam Neeson</actor>"
        "<actor id=\"3\">Michael Caine</actor>"
    "</actors>"
    "<foo:singers>"
        "<foo:singer id=\"4\">Tom Waits</foo:singer>"
        "<foo:singer id=\"5\">B.B. King</foo:singer>"
        "<foo:singer id=\"6\">Ray Charles</foo:singer>"
     "</foo:singers>"
"</root>";

Action() {
int find_cnt;
    lr_save_string(xml_input, "XML_Input_Param");

    lr_xml_extract(
    "XML={XML_Input_Param}",
    "XMLFragmentParam=Result",
    "Query=//actor[1]/@id",
    LAST
);

lr_output_message(lr_eval_string("Extracted: {Result}"));

return 0;
}