Pragmatics__Inc
14 years agoOccasional Contributor
Accessing Child Nodes with getXmlHolder
I have to verify the child nodes of a list of nodes in an XML response. I'm doing the following:
This works, but is rather slow and seems 'ungroovy'. I was wondering if there is a way to access the item I am actually iterating on to get at it's children, like
or if I can avoid creating the item altogether to save memory and perhaps speed up the query.
Is there a way to do either to avoid having to count the items or is this the best way to do this?
def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
def holder = groovyUtils.getXmlHolder( messageExchange.responseContentAsXml )
holder.namespaces["plan"] = "SOMEURL/plan"
ii = 1
for ( item in holder.getNodeValues("//rr:GetAllUlnResponse[1]/plan:ULN") ){
if ( holder.getNodeValue("//rr:GetAllUlnResponse/plan:ULN[$ii]/RDL[1]") != "374" ) {
assert false
}
else if ( holder.getNodeValue("//rr:GetAllUlnResponse/plan:ULN[$ii]/STIC[1]") != "N" ) {
assert false
}
ii = ii + 1
}
assert true
This works, but is rather slow and seems 'ungroovy'. I was wondering if there is a way to access the item I am actually iterating on to get at it's children, like
pseudocode: if (item.RDL[1].value != "374") {
or if I can avoid creating the item altogether to save memory and perhaps speed up the query.
Is there a way to do either to avoid having to count the items or is this the best way to do this?