There are 2 problems in XML and its not valid
attr2:"Sample" should be attr2="Sample"
testns is not declared , it should be xmlns:testns="http://www.sample.com
So the correct XML is
<testns:TestResult xmlns:testns="http://www.sample.com" attr1="100" attr2="Sample">
<testns:TestToken>XXXXXX</testns:TestToken>
</testns:TestResult>
Lets assume the name of this XML is **Request1**
so the groovy Code that can get the attribute is
def req=groovyUtils.getXmlHolder("Request1#Request")
def attr1=req.getNodeValue("//*:TestResult/@attr1")
log.info "Value of attr1 is " + attr1
def attr2=req.getNodeValue("//*:TestResult/@attr2")
log.info "Value of attr2 is " + attr2
The code which can get attribute is the xpath **//*:TestResult/@attr2**
if the XML is stored in response you can use Request1#Response instead of Request.
Additionally if you want to get value between tags use below code
def testtoken=req.getNodeValue("//*:TestResult/*:TestToken")
log.info "Value of testtoken is " + testtoken
