Extract second CDATA content with RegEx or XPath in JMeter

谁都会走 提交于 2020-01-05 07:31:08

问题


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>

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.

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

Thanks in advance...


回答1:


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


来源:https://stackoverflow.com/questions/26912892/extract-second-cdata-content-with-regex-or-xpath-in-jmeter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!