Can I use XmlSlurper directly on the w3c.dom.Node object

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

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

I get instances com.sun.org.apache.xerces.internal.dom.ElementNSImplcoming out of a WebService call.

I can call new XmlSlurper().parseText(it as String)where itis an instance ElementNSImpl.

However, of course, this writes the Element to a string before redrawing and tearing it apart. Is there any way to avoid this unnecessary step?

Ultimately, I want to turn a fragmented object into a Groovy Bean; There is a better way to do this. I was curious about DomToGroovy, but it still gives me the line that I then ran in the Groovy shell.

+3
source share
1 answer

I do not think that XmlSlurper supports such direct conversions, you probably have to write something yourself. Perhaps if you delve into the source of XmlSlurper, this will be the way to do this by expanding and adding a new parse () method. Otherwise, if you do not have serious performance problems, I would say that you are on the right track.

+1
source

All Articles