« Return to Thread: How to format xml from XmlSlurper?

Re: How to format xml from XmlSlurper?

by Robert Fischer :: Rate this Message:

Reply to Author | View in Thread

Feel free to define "toIndentedString()" to do what you want it to do on NodeChild (or whatever).

I don't think XmlSlurper was really developed with an eye towards outputting code, so it's not
surprising you're finding it lacking in that department.

~~ Robert.

Steve Tekell wrote:

> I am looking for an easy, groovy way to format the string output of
> XmlSlurper.
>
> I have found examples of using XmlParser and XmlNodePrinter.  This won't
> work.  XmlNodePrinter works with the Node from XmlParser, but not NodeChild
> from XmlSlurper.
>
>
> // this prints nothing (nor does it throw an error)
> def responseXml = new XmlSlurper().parseText(serviceResponse)
> def writer = new StringWriter()
> new XmlNodePrinter(new PrintWriter(writer)).print(responseXml)
> def formattedResponse = writer.toString()
> println "formattedResponse:" + formattedResponse
>
>
> Is there anyway to get that to work with XmlSlurper?
> Or better, is there a more groovy way of doing this?
> That takes multiple lines/constructors to effectively do what I wish was
> just
>
> xml.toIndentedString()
>
>
> thanks,
>
> Steve
>

--
~~ Robert Fischer, Smokejumper IT Consulting.
Enfranchised Mind Blog http://EnfranchisedMind.com/blog

Check out my book, "Grails Persistence with GORM and GSQL"!
http://www.smokejumperit.com/redirect.html

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


 « Return to Thread: How to format xml from XmlSlurper?