Scala to extract XML from SOAPUI-project file

I’ve created a small scala-script to extract messages from SOAPUI. Writing this was surprisingly easy, and certainly faster and more pleasant then processing the SOAPUI manually.

import scala.xml._
import java.io._
/**
* Small script to extract the request-xml-messages from a soapui project
*/
object SoapUIExtractor extends App {
def writeTestStep(teststep:Node) {
val requestContent = (teststep \ "config" \ "restRequest" \ "request").head.child(0).text
val testCaseName = (teststep \ "@name").head.text
val filename = testCaseName+".xml"
println(filename)
val writer = new PrintWriter(new File( filename ))
writer.write(requestContent)
writer.close()
println(requestContent)
}
val soapUI = XML.loadFile("my_soapui-project.xml")
//extract all test cases and write the request-xml that's contained in each test-case
(soapUI \\ "soapui-project" \ "testSuite" \ "testCase" \ "testStep" ).foreach ( r => writeTestStep(r) )
}