1 Reply Latest reply on Jun 5, 2009 4:11 AM by 794254

    Generate XML file Dynamically

      We want to generate an xml file for the given folder in file system. This XML should contain nested nodes for all subfolders and files. Please could any one help me with logic to generate xml?

      Sample of XML

      Thanks in advance.
        • 1. Re: Generate XML file Dynamically
          Welcome to the Sun forums.

          1. Please post your code using code tags, this formats it so that it is easier for people to read and understand it. Click on 'CODE' above the text area when posting.
          2. As far as possible, please post an SSCCE
          3. Please explain what you are trying, what you're expecting and what you're getting. Don't expect to be spoon-fed the answer without putting in any work.

          The very simplest way would be to simply write all the nodes yourself:
          FileWriter writer = new FileWriter(new File("myXML.xml"));
          But this is pretty brittle and prone to errors and would only work for the most trivial files. If you want robust XML support then you should use some library like perhaps jdom