DocumentFactory docFactory = new DocumentFactory(); Document document = docFactory.createDocument(); Dom4JXMLOutput treeBuilder = new Dom4JXMLOutput(document); bugCollection.writeXML(treeBuilder, getProject());
Document document = bugCollection.toDocument(getProject()); new AddMessages(bugCollection, document).execute();
	public void finish() {		try {			// Get the XML Document with the saved bugs			generateSummary();			BugCollection bugCollection = getBugCollection();			DocumentFactory docFactory = new DocumentFactory();			Document document = docFactory.createDocument();			Dom4JXMLOutput treeBuilder = new Dom4JXMLOutput(document);			bugCollection.writeXML(treeBuilder, getProject());			// Get the stylesheet as a StreamSource			InputStream xslInputStream =			        this.getClass().getClassLoader().getResourceAsStream(stylesheet);			if (xslInputStream == null)				throw new IOException("Could not load HTML generation stylesheet " + stylesheet);			StreamSource xsl = new StreamSource(xslInputStream);			// Create a transformer using the stylesheet			TransformerFactory factory = TransformerFactory.newInstance();			Transformer transformer = factory.newTransformer(xsl);			// Source document is the XML generated from the BugCollection			DocumentSource source = new DocumentSource(document);			// Write result to output stream			StreamResult result = new StreamResult(outputStream);			// Do the transformation			transformer.transform(source, result);		} catch (Exception e) {			logError("Could not generate HTML output: " + e.toString());		}	}