I have a list of strings that i want to convert to xml. How would I do so using DOM? I'm not sure how to create a Document using the strings to use as a Source to generate the XML.
Can anyone show me a sample code to generate a Document? For example the XML would be like:
ArrayList<String> fruits
<Fruits>
<fruit>Apple<fruit>
<fruit>Grape<fruit>
<Fruits>
I think the code would be:
TransformerFactory transFact = TransformerFactory.newInstance();
Transformer serializer = transFact.newTransformer();
Properties props = new Properties();
props.put("method", "xml");
props.put("indent", "yes");
serializer.setOutputProperties(props);
Source source = new DOMSource(document); //need to create a document
Result result = new StreamResult(PrintWriter);