Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.0k views
in Technique[技术] by (71.8m points)

xml - Looping through data in JMeter and storing data to use in other sampler

I have following data in XML response in JMeter:

<details>
<srNo>1</srNo>
<key>123</key>
<Name>Inspector</piName>
<age>89</age>
<country>India</country>
</details>
....................................
...................................
<details>
<srNo>1</srNo>
<key>123</key>
<Name>Inspector</piName>
<age>89</age>
<country>America</country>
</details>

suppose I have n number of such data, from the response of the XML file. I want to read value of "key". for eg. 1 I have to read "1" and store in a variable. For 1 such response i am reading it in XPath extractor and getting the correct value, but now I have to loop through it to get specified amount of key value in a variable. Suppose if I want 1000 such keys then I have to loop till 1000 times to get all the value in variables.

After getting that value in variables I have to used that value in another Sampler for eg: ${key1}

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The above example code works for me however is missing one import:

import org.xml.sax.InputSource;

As the line:

InputSource is = new InputSource(new StringReader(result.getResponseDataAsString()));

requires InputSource to be imported.

After that it works perfectly for me.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...