3
votes

Below mentioned XML is a sample xml, like this there are 'N' number of nodes available and I want to read XML attribute in Beanshell post processor. I get this XML from the HTTP request. How to read that XML (HTTP Response) in Jmeter beanshell post processor like we read in java?

 <Order OrderNo="Y1101001">
     <OrderLines>
       <OrderLine LineNo="1" LineKey="20171100011"> 
       <OrderLine LineNo="2" LineKey="20171100012">
      </OrderLines>
     </Order>
2

2 Answers

1
votes

Here you can find beanshell/java code to extract values from xml:

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

1
votes

Beanshell is more or less Java compatible, therefore you can use plain Java code to parse XML.

However I would recommend considering JSR223 PostProcessor and Groovy language instead, Groovy is better from performance point of view, moreover it has built-in XML support so you will be able to get the count of your OrderLine elements as simple as:

def response = new XmlParser().parseText(prev.getResponseDataAsString()) 
def size = response.OrderLines.OrderLine.size()
log.info("Size: " + size)

Demo:

JMeter JSR223 XML

References: