I am attempting to generate an XML file from some data, and then download the file using PrimeFaces but I cannot put all the pieces together to accomplish this.
My code for generating the xml file is below:
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
Document doc = docBuilder.newDocument();
Element rootElement = doc.createElement("RoutePaths");
doc.appendChild(rootElement);
Attr attribute = doc.createAttribute("xmlns");
attribute.setValue("http://tempuri.org/RoutePath.xsd");
rootElement.setAttributeNode(attribute);
for(RssmXml record : xmlList)
rootElement.appendChild(buildRoutePath(doc,record));
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
DOMSource source = new DOMSource(doc);
StreamResult result = new StreamResult(new File("someFile.xml"));
transformer.transform(source, result);
I have left out the method call for "buildRoutePath", but this just generates the xml.
How do I take this generated xml file and download it using PrimeFaces file download? http://primefaces.org/showcase/ui/file/download.xhtml
I can see using this link that it is possible, but I would prefer to use the file, and not convert the XML to a string.