Element element = document.createElement("author"); Document document = element.getOwnerDocument();
Transformer transformer = TransformerFactory.newInstance().newTransformer(); DOMSource source = new DOMSource(element.getOwnerDocument()); StreamResult result = new StreamResult(outputStream); transformer.transform(source, result);In this example, we create a new Transformer object using the TransformerFactory class. We then create a DOMSource object using the getOwnerDocument method on an element. This allows us to transform the XML contained in the document to another format, such as a StreamResult. Package library: javax.xml.parsers.