我使用xquery和BaseX尝试以我想要的格式从JMeter测试用例(.jmx文件)中检索信息。
这是我实际运行的代码(在BaseX GUI中):
let $rlist := db:list("JMeter")
for $resource in $rlist
let $rcontent := db:open("JMeter", $resource)
let $ret :=
<HttpRequest>
{
for $item in $rcontent/jmeterTestPlan//HTTPSamplerProxy
return
(<method>
{
$item/stringProp[attribute()/string() = "HTTPSampler.method"]/text()
}
</method>,
<path>
{
let $parse := $item/stringProp[attribute()/string() = "HTTPSampler.path"]/text()
let $parse := fn:replace($parse, "\?[^/]*", "")
let $parse := fn:replace($parse, "\$[^/]*", "\${}")
let $parse := fn:replace($parse, "[0-9]+", "\${}")
return $parse
}
</path>,
<resource>
{
$resource
}
</resource>)
}
</HttpRequest>
return
<HttpRequests>
{
$ret
}
</HttpRequests>
生成的xml如下所示:
<HttpRequests>
<HttpRequest>
<method>POST</method>
<path>/config</path>
<resource>CentralConfiguration/Requests/addConfiguration.jmx</resource>
</HttpRequest>
</HttpRequests>
<HttpRequests>
<HttpRequest>
<method>POST</method>
<path>/propertyType</path>
<resource>CentralConfiguration/Requests/addPropertyType.jmx</resource>
</HttpRequest>
</HttpRequests>
...
这是我期望的结果:
<HttpRequests>
<HttpRequest>
<method>POST</method>
<path>/config</path>
<resource>CentralConfiguration/Requests/addConfiguration.jmx</resource>
</HttpRequest>
<HttpRequest>
<method>POST</method>
<path>/propertyType</path>
<resource>CentralConfiguration/Requests/addPropertyType.jmx</resource>
</HttpRequest>
...
</HttpRequests>
我非常感谢格式化我的xquery以获得预期结果的帮助,谢谢
答案 0 :(得分:0)
通过将外部for循环放在第一个标签内来解决问题。