LoadRunner 12.55 Cannot convert 'string' to 'string' 执行xpath字符串函数时报错

LoadRunner 12.55 Cannot convert 'string' to 'string' error while executing xpath string function

我有这个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
);

出现错误:

Cannot convert 'string' to 'string'

我的错误在哪里?

您使用了错误的 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;
}