Here you can find the source of createXml(ArrayList
public static void createXml(ArrayList<String> nameList, ArrayList<String> stringList, ArrayList<String> stringArrayNameList, HashMap<Integer, ArrayList<String>> stringArrayContentMap)
//package com.java2s; //License from project: Apache License import java.io.File; import java.util.ArrayList; import java.util.HashMap; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerConfigurationException; import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerFactory; import javax.xml.transform.TransformerFactoryConfigurationError; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; import org.w3c.dom.*; public class Main { public static void createXml(ArrayList<String> nameList, ArrayList<String> stringList, ArrayList<String> stringArrayNameList, HashMap<Integer, ArrayList<String>> stringArrayContentMap) { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = null; try {/*from w ww . j a v a2 s.co m*/ builder = factory.newDocumentBuilder(); Document document = builder.newDocument(); Element mainRootElement = document .createElementNS("xmlns:xliff=\"urn:oasis:names:tc:xliff:document:1.2\"", "resources"); document.appendChild(mainRootElement); for (int t = 0; t < nameList.size(); t++) { mainRootElement.appendChild(getNode(document, "string", nameList.get(t), stringList.get(t))); } for (int i = 0; i < stringArrayNameList.size(); i++) { Node stringArrayNode = getNode(document, "string-array", stringArrayNameList.get(i), null); for (int j = 0; j < stringArrayContentMap.get(i).size(); j++) { stringArrayNode .appendChild(getNode(document, "item", null, stringArrayContentMap.get(i).get(j))); } mainRootElement.appendChild(stringArrayNode); } Transformer transformer = TransformerFactory.newInstance().newTransformer(); // transformer.setOutputProperty(name, value); DOMSource source = new DOMSource(document); StreamResult result = new StreamResult(new File("out.xml")); transformer.transform(source, result); } catch (ParserConfigurationException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (TransformerConfigurationException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (TransformerFactoryConfigurationError e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (TransformerException e) { // TODO Auto-generated catch block e.printStackTrace(); } } private static Node getNode(Document document, String nodeName, String attrName, String value) { Element node = document.createElement(nodeName); if (attrName != null) { node.setAttribute("name", attrName); } node.setTextContent(value); return node; } }