Forum Discussion

Bichoo's avatar
Bichoo
New Contributor
13 years ago

How to remove nodes on some condition

HI

I have been trying to remove the nodes which have '?'(question mark) as value , from my soapui request. I am using xmlHolder() for this ,following is the groovy code

for(TS in project.testSuiteList) {
for(TC in TS.testCaseList) {
for(TStp in TC.testStepList) {
if(TStp instanceof WsdlTestRequestStep){

def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
def req=TStp.getPropertyValue("Request")
def request = context.expand(req)
def holder = groovyUtils.getXmlHolder( TStp.testRequest.requestContent )

use (groovy.xml.dom.DOMCategory) {
for( node1 in holder.getDomNodes( "//pay:orderData" )) {
node1.children().each { child ->

if(child.text()=="?"){
node1.parentNode.removeChild( node1 )
}
}
}
}
}

}
}
}

but this block of code is not working for me .. . I dont want to use xmlparser or xmlslurper for this . I am very badly struck in this .. Any help would be grtly appropriated

Regrads
Bichoo

3 Replies

  • nmrao's avatar
    nmrao
    Community Hero
    What is happen with the code you have posted ? That will help understanding little more than someone trying out the code.
  • Bichoo's avatar
    Bichoo
    New Contributor
    i am getting a NullPointerException at this line- "use (groovy.xml.dom.DOMCategory) "
  • nmrao's avatar
    nmrao
    Community Hero
    Not have much idea about "use"
    Another way is to read it line by line and use patten match to remove. I do see pattern "[>?</]" which you want to remove.