Alex Rivera | Logout

How to I output org.w3c.dom.Element to string format in java?

Asked 2009-08-02T19:21:52.623
101

I have an org.w3c.dom.Element object passed into my method. I need to see the whole xml string including its child nodes (the whole object graph). I am looking for a method that can convert the Element into an xml format string that I can System.out.println on. Just println() on the 'Element' object won't work because toString() won't output the xml format and won't go through its child node. Is there an easy way without writing my own method to do that? Thanks.

Edit
Report

1 Answer

2

Not supported in the standard JAXP API, I used the JDom library for this purpose. It has a printer function, formatter options etc. http://www.jdom.org/

answered 2009-08-02T20:02:33.010

Your Answer