Not able to loop over XML tags in groovy properly

后端 未结 1 1579
滥情空心
滥情空心 2021-01-27 05:10

I was able to send a webrequest by soapUI which gives me data in XML format as response .I want to insert the value of xml tag in database tables.

This is what I have t

1条回答
  •  梦毁少年i
    2021-01-27 05:40

    Because your data is in a CDATA block, it is treated as a String (and then needs to be re-parsed as it is XML)

    // Parse the xml
    def xml =  new XmlSlurper().parseText(response)
    
    // Get the cdata text
    def cdata = xml.Body.executeXMLQueryResult.return.rowset.text()
    
    // Re-parse it
    def innerXml = new XmlSlurper().parseText(cdata)
    
    // Then iterate the rows
    innerXml.Row.each { row ->
        println row.Column0.text()
    }
    

    0 讨论(0)
提交回复
热议问题