title: Converting JTree to Xml in java
body: <p>I am working on JTree and i need to Create XML file of Jtree so is there any good way to convert it? I am using JTree in java.
  I just need to convert it and i have <code>Checkbox</code> as node into the Tree and i have used render for it. and when submit call i need to convert  that Jtree into XML. is there any good way for that??</p>
  
  <p>My Tree is Dynamically Created. so i need to convert it.</p>
  
  <p>i tried this</p>
  
  <pre><code>try {
              DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
              Document doc = factory.newDocumentBuilder().newDocument();
              Element rootElement = doc.createElement("Vervesystems");
  
              TreeNode root = (TreeNode) jTree1.getModel().getRoot();
  
              parseTreeNode(root, rootElement);
              System.out.println("Node name"+root.toString());
              System.err.println("Root node"+root.getChildCount());
  
              Transformer tf = TransformerFactory.newInstance().newTransformer();
              tf.setOutputProperty(OutputKeys.INDENT, "yes");
              tf.setOutputProperty(OutputKeys.METHOD, "xml");
              tf.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
  
              DOMSource domSource = new DOMSource(doc);
              StreamResult sr = new StreamResult(new File("/home/kishan/NetBeansProjects/03-02-2014-VISDashboard/src/com/verve/visdashboard/TreeModel.xml"));
              tf.transform(domSource, sr);
  
  
          } catch (Exception e) {
              System.err.println("This is exception "+e);
  
          }
  
  private void parseTreeNode(TreeNode treeNode, Node doc) {
          try {
          Element parentElement = doc.getOwnerDocument().createElement("folder");
          doc.appendChild(parentElement);
  
          System.err.println("Element name"+parentElement.getTagName());
  
          // Apply properties to root element...
          org.w3c.dom.Attr attrName = doc.getOwnerDocument().createAttribute("DisplayName");
          attrName.setNodeValue("Treenode");
          System.err.println("Count"+treeNode.getChildCount());
          parentElement.getAttributes().setNamedItem(attrName);
  
  
          Enumeration kiddies = treeNode.children();
  
          while (kiddies.hasMoreElements()) {
              TreeNode child = (TreeNode) kiddies.nextElement();
              //doc.appendChild(child);
              System.out.println("Child"+child.toString());
              parseTreeNode(child, parentElement);
          }
  
          } catch (Exception e) {
              System.err.println("exception is here"+e);
          }
  </code></pre>
  
  <p>but its Wrting blank only in myxml file. can anybody give suggestion. Example image is here.
  <img src="https://i.stack.imgur.com/ZtgNG.png" alt="enter image description here"></p>