By Antony Reynolds-Oracle on May 22, 2007
Printing XMLA question came up at the end of last week from a colleague "In Java how do I convert a DOM document object into a string?"
So the basic problem is that 'toString' on an 'org.w3c.dom.Element or 'org.w3c.dom.Document' does not, as you might expect, return a string representation of an XML document, but rather returns the object identifier. A closer look reveals that there seems to be no other function on Document or Element to convert the DOM (Document Object Model) to a String.
So here is an answer.
First of all create an empty org.w3c.dom.XMLTransform.
javax.xml.transform.Transformer xform = tfactory.newTransformer();
Result javax.xml.transform.result = new javax.xml.transform.stream.StreamResult(writer);
All this leaves you wondering why Element does not have an generateXmlAsString() method...