3

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.

Ben Hammond
  • 705
  • 1
  • 7
  • 20

1 Answers1

1

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.

paradoxbomb
  • 414
  • 5
  • 8
  • yeah, I'd need to create a GPathResult, but it won't accept the ElementNSImpl instance, so I'd have to convert that into an object it WOULD accept; Perhaps I could write an interface adapter to do that, but its sounding like alot of trouble. Easier just to live with the string conversion .... – Ben Hammond May 25 '11 at 21:00