nbpeth
nbpeth

Reputation: 3148

Groovy - XML Slurper Parse SoapResponse instead of File

I'm trying to parse a SOAP object - I am looking at the XML slurper in Groovy, but it wants to read from an XML file. I would prefer to avoid the file (there are going to be millions of lines, writing to a file isn't too practical) - is there a way to pass the SOAPResponse object to XMLSluper instead of a file?

SOAPMessage soapResponse;

Upvotes: 0

Views: 555

Answers (2)

Oren Yosifon
Oren Yosifon

Reputation: 927

  • XmlSluprer can read XML from arbitrary sources, not just a file. You can do somehting like:

    InputStream in = ...// point to your data stream
    def parsedData = new XmlSlurper().parse(in)

That will get you the SOAP object as a GPathResult you can manipulate.

  • if this is a valid SOAP object, from a source whose schema is stable, you might be better off using a mechanism which was intended to do just that in the first place. You can either use the classic java JAXB mechanism, or do in in a more groovy way using GroovyWS .

Good luck !

Upvotes: 1

Dónal
Dónal

Reputation: 187379

XMLSlurper provides a series of overloaded parse methods and a parseText method that can read XML input in the following formats

  • File
  • InputSource
  • InputStream
  • Reader
  • String
  • URI

You didn't mention the type of your SOAPResponse object, but it's highly likely it's one of the above (or can easily be converted to one of these).

Upvotes: 2

Related Questions