title: How to declare doctype ,xml version and encoding in XML file using DOM parser in java?
body: <p>For sorry, I don't know how to attempt to do such thing.</p>
  
  <pre><code>public void writeXML(String tableName) {
      try {
          DocumentBuilderFactory docFactory = DocumentBuilderFactory
                  .newInstance();
          DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
  
          // root elements
          Document doc = docBuilder.newDocument();
          Element rootElement = doc.createElement(tableName);
          doc.appendChild(rootElement);
  
          for(Map m: rows){
              Element parent = doc.createElement((String) m.get("ownerNode"));
              rootElement.appendChild(parent);
              for(String s: colNames){
                  String key = (String) m.get(s);
                  System.out.println(key);
                  Element innerNode = doc.createElement(s);
                  innerNode.appendChild(doc.createTextNode((String) m.get(s)));
                  parent.appendChild(innerNode);
              }
          }
  
  
  
          // write the content into xml file
          TransformerFactory transformerFactory = TransformerFactory
                  .newInstance();
          Transformer transformer = transformerFactory.newTransformer();
          DOMSource source = new DOMSource(doc);
          StreamResult result = new StreamResult(new File(tableName + ".xml"));
  
          // Output to console for testing
          // StreamResult result = new StreamResult(System.out);
  
          transformer.transform(source, result);
  
          System.out.println("File saved!");
  
      } catch (ParserConfigurationException pce) {
      } catch (TransformerException tfe) {
      }
  
  }
  </code></pre>
  
  <p>this is my code to write the body of the xml so it would be greatly appreciated if can anybody help me to add XML version,encoding, doctype and DTD reference with DOM parser</p>