Forum Discussion

KaviSwami's avatar
12 years ago

XML parsing using groovy

Hi,

I am new to SOAP UI and groovy.In my web service the response has multiple (more than 200) XML nodes with different name spaces. I have to read the xml element values and attributes for each node and compare them against the corresponding database values. My question is how do I parse the response XML to get each element name and its value (name/value pair) for each node. Please help me with any sample code.

Thanks in advance.
Abhi
  • PaulDonny's avatar
    PaulDonny
    Regular Contributor
    def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context);
    def holder = groovyUtils.getXmlHolder(testName+"#Request");
    def xml = holder.getPrettyXml();
    def regexp = ("<([^<>]+)>(.*?)</\\1>");
    def matcher = xml =~ regexp;
    matcher.each {

    }


    it[1] will be your XML tag, it[2] will be the value from it. This will only work for situations where the tags are "<xml>value</xml>". This does loop through every single value.