在JMeter中使用RegEx或XPath提取第二个CDATA内容 [英] Extract second CDATA content with RegEx or XPath in JMeter

查看:141
本文介绍了在JMeter中使用RegEx或XPath提取第二个CDATA内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从JMeter中的响应中提取第二个CDATA元素的内容.响应看起来像这样:

I need to extract the content of the second CDATA element from a response in JMeter. The response looks for example like this:

<?xml version='1.0' encoding='UTF-8'?>
<partial-response><changes><update id="layout:layoutLeft:treeForm:riverTree">
<![CDATA[<li id="layout:layoutLeft:treeForm:flussgebieteBaum:0_0_0" data-rowkey="0_0_0" 
class="ui-treenode ui-treenode-parent river default" role="treeitem">
<span class="ui-treenode-content ui-tree-selectable" aria-expanded="false" aria-selected="false">
<span class="ui-tree-toggler ui-icon ui-icon-triangle-1-e"></span><span></span>
<span class="ui-treenode-label ui-corner-all"><span title="W">W</span></span>
<span class="hwims-markingSpan"></span></span><ul class="ui-treenode-children" style="display:none">
</ul></li>]]></update><update id="javax.faces.ViewState">
<![CDATA[5518082394550102028:7288540440023391844]]></update></changes></partial-response>

我需要的内容是第二个CDATA的 5518082394550102028:7288540440023391844 (它是JSF ViewState,所以也可能是1369398461548266266354:-388879175942962262).第一个CDATA元素的内容也会更改.

The content I need is 5518082394550102028:7288540440023391844 of the second CDATA (it is a JSF ViewState, so it could also be 1369398461548266354:-388879175942962262). The content of the first CDATA element also changes.

我该如何提取?还是可以使用XPath?

How can I extract that? Or is it possible to use XPath?

预先感谢...

推荐答案

\[CDATA\[([^\]]+)(?![\s\S]*\[CDATA)

尝试一下.抓拍.请参见演示.

Try this.Grab the capture.See demo.

http://regex101.com/r/pQ9bV3/9

var re = /\[CDATA\[([^\]]+)(?![\s\S]*\[CDATA)/g;
var str = '<?xml version=\'1.0\' encoding=\'UTF-8\'?>\n<partial-response><changes><update id="layout:layoutLeft:treeForm:riverTree">\n<![CDATA[<li id="layout:layoutLeft:treeForm:flussgebieteBaum:0_0_0" data-rowkey="0_0_0" \nclass="ui-treenode ui-treenode-parent river default" role="treeitem">\n<span class="ui-treenode-content ui-tree-selectable" aria-expanded="false" aria-selected="false">\n<span class="ui-tree-toggler ui-icon ui-icon-triangle-1-e"></span><span></span>\n<span class="ui-treenode-label ui-corner-all"><span title="W">W</span></span>\n<span class="hwims-markingSpan"></span></span><ul class="ui-treenode-children" style="display:none">\n</ul></li>]]></update><update id="javax.faces.ViewState">\n<![CDATA[5518082394550102028:7288540440023391844]]></update></changes></partial-response>';
var m;

while ((m = re.exec(str)) != null) {
if (m.index === re.lastIndex) {
re.lastIndex++;
}
// View your result using the m-variable.
// eg m[0] etc.
}

这篇关于在JMeter中使用RegEx或XPath提取第二个CDATA内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆