Check out this other answer from stackoverflow.
You would use a DOMSource (instead of a StreamSource) and pass the node in the constructor.
Then you can convert node to string.
Quick example:
public class NodeToString { public static void main(String[] args) throws TransformerException, ParserConfigurationException, SAXException, IOException {
Paul grime
source share