Hi.. I am new to XML and DOM.I'm trying to output an XML document.I am using LinkedHashMap as the input to provide elements and subelements. The code is:
//No generics private LinkedHashMap table; private Document dom; Element rootEle; Element one;
public Test(LinkedHashMap table) { //create a list to hold the data this.table = table; //Get a DOM object createDocument(); createDOMTree(); printToFile(); }
private void createDOMTree() {
//create the root element <Reports> rootEle = dom.createElement("Report");
//print OutputFormat format = new OutputFormat(dom); format.setIndenting(true); //to generate a file output use fileoutputstream instead of system.out XMLSerializer serializer = new XMLSerializer(new FileOutputStream(new File("C:/java/JavaApplication6/a.xml")), format);
//get an instance of factory DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); try { //get an instance of builder DocumentBuilder db = dbf.newDocumentBuilder();
//create an instance of DOM dom = db.newDocument();