Java Document to String
This is a very simple utility function to produce an indented XML document as a String given a Document. It throws a TransformerException if anything drastic goes wrong.
import java.io.*; import org.w3c.dom.Document; import javax.xml.transform.*; import javax.xml.transform.dom.DOMSource; ... public static String documentToString( Document document ) throws TransformerException { TransformerFactory tFactory = TransformerFactory.newInstance(); Transformer transformer = tFactory.newTransformer(); DOMSource source = new DOMSource(document); StringWriter sw = new StringWriter(); StreamResult result = new StreamResult(sw); transformer.setOutputProperty( OutputKeys.INDENT, "yes" ); transformer.transform(source, result); return sw.toString(); }
$ subscribe --newsletter
Practical AI engineering, in your inbox
Field notes for technical leaders building agents, evaluation systems, governance, and production infrastructure.
Related
Can a Human Finish the Work When the Agent Stops?
A manual takeover needs control of the next write, evidence of completed work and a way to resolve effects whose outcome is still unknown.
Parallel Agents Need More Than Separate Branches
Separate worktrees help with file edits; an ownership map makes shared databases, ports, contracts and integration checks explicit.
Your Tests Passed. Which Revision Is Running?
A release receipt should connect the tested candidate, built artifact, deployment and production route without pretending one smoke check proves everything.