Question

I am experimenting with GroovyWS in the hope of completely replacing Axis2 client code.

One of the Webservice operations I call returns fragments of XML, which I need to turn into Groovy Beans.

I am getting instances of com.sun.org.apache.xerces.internal.dom.ElementNSImpl coming out of the WebService call.

I can call new XmlSlurper().parseText(it as String) where it is the instance of ElementNSImpl.

However, of course this writes the Element out to a String before reparsing and slurping it. Is there a way to avoid this unnecessary step ?

Ultimately I want to turn the slurped object into a Groovy Bean; is there a better way to do this. I was wondering about DomToGroovy, but this still gives me a string that I then have run in a Groovy Shell.

Était-ce utile?

La solution

I don't think XmlSlurper supports direct conversions like that, you'd probably have to write something yourself. Maybe if you dig in to the XmlSlurper source there will be a way to do it by extending and adding a new parse() method. Otherwise, unless you have major performance concerns, I'd say you're on the right track.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top