【问题标题】:Extract second CDATA content with RegEx or XPath in JMeter在 JMeter 中使用 RegEx 或 XPath 提取第二个 CDATA 内容
【发布时间】:2014-11-13 15:51:10
【问题描述】:

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

<?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,所以也可以是1369398461548266354:-388879175942962262)。第一个 CDATA 元素的内容也会发生变化。

我怎样才能提取它?或者是否可以使用 XPath?

提前谢谢...

【问题讨论】:

    标签: regex jsf xpath jmeter viewstate


    【解决方案1】:
    \[CDATA\[([^\]]+)(?![\s\S]*\[CDATA)
    

    试试这个。抓住捕获。查看演示。

    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.
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-10-11
      • 2011-05-25
      • 2021-09-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多