displaying output in the displayed xml format
<p>I need a help in writing the java code to display the output in the following format,</p>

<p>Please help me in correcting this java file and print the output in the correct format.</p>

<pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;CBB&gt;
&lt;CSV CKK="Folder_1"&gt;
    &lt;SV_File CKK="File_1"&gt;
        &lt;SV CKK="Line_1"/&gt;
        &lt;SV CKK="Line_2"/&gt;
        &lt;SV CKK="Line_3"/&gt;
        &lt;SV CKK="Line_4"/&gt;
        &lt;SV CKK="Line_5"/&gt;
        &lt;SV CKK="Line_6"/&gt;
        &lt;SV CKK="Line_7"/&gt;
        &lt;SV_Depend DependentVariableID="File_1" SourceVariableID="Line_1"/&gt;
        &lt;SV_Depend DependentVariableID="File_1" SourceVariableID="Line_2"/&gt;
        &lt;SV_Depend DependentVariableID="File_1" SourceVariableID="Line_3"/&gt;
        &lt;SV_Depend DependentVariableID="File_1" SourceVariableID="Line_4"/&gt;
        &lt;SV_Depend DependentVariableID="File_1" SourceVariableID="Line_5"/&gt;
        &lt;SV_Depend DependentVariableID="File_1" SourceVariableID="Line_6"/&gt;
        &lt;SV_Depend DependentVariableID="File_1" SourceVariableID="Line_7"/&gt;
    &lt;/SV_File&gt;
    &lt;SV_File CKK="File_2"&gt;
        &lt;SV CKK="Line_1"/&gt;
        &lt;SV CKK="Line_2"/&gt;
        &lt;SV CKK="Line_3"/&gt;
        &lt;SV CKK="Line_4"/&gt;
        &lt;SV CKK="Line_5"/&gt;
        &lt;SV CKK="Line_6"/&gt;
        &lt;SV CKK="Line_7"/&gt;
        &lt;SV_Depend DependentVariableID="File_2" SourceVariableID="Line_1"/&gt;
        &lt;SV_Depend DependentVariableID="File_2" SourceVariableID="Line_2"/&gt;
        &lt;SV_Depend DependentVariableID="File_2" SourceVariableID="Line_3"/&gt;
        &lt;SV_Depend DependentVariableID="File_2" SourceVariableID="Line_4"/&gt;
        &lt;SV_Depend DependentVariableID="File_2" SourceVariableID="Line_5"/&gt;
        &lt;SV_Depend DependentVariableID="File_2" SourceVariableID="Line_6"/&gt;
        &lt;SV_Depend DependentVariableID="File_2" SourceVariableID="Line_7"/&gt;
    &lt;/SV_File&gt;
&lt;/CSV&gt;
</code></pre>

<p></p>

<p>I have 2 folders(Folder_1 and Folder_2) inside a folder(abcd). Inside the Folder_1, I have 2 files "File_1" and "FIle_2".</p>

<p>Inside "file_1", i have 7 lines of code liek Line_1, Line_2... Line_7...</p>

<p>I am finding the  tag closing in many places. I need that to be closed when it finishes the Folder_1 only.</p>

<pre><code>import java.io.*;
import java.util.*;
import java.lang.String;

public class Vardeps {
public static void main(String args[]) throws FileNotFoundException
{
    // File Writer for the XML
    FileWriter fostream;
    PrintWriter out = null;     
    String strOutputPath = "D:\\Current_\\";
    String strFilePrefix = "Temp";
    String filesListTrim;
    int intID = 1;

    // Read the file name for the SodaSystem
    File startingDirectory= new File("D:\\Current_\\Additional_Files\\abcd");
    List&lt;File&gt; filesList = FileListing.getFileListing(startingDirectory);
    File file = new File("D:\\Current_\\Additional_Files\\abcd");

    File[] files = file.listFiles();  
    String[] children = file.list();


    // Try for the SodaSystem.
    try{
    if(children == null)
    {
       // no files exist.
        System.out.println("no files exist");
    }
    else
    {
        // For the SodaSystem
        fostream = new FileWriter(strOutputPath+"\\"+strFilePrefix+".xml");
        out = new PrintWriter(new BufferedWriter(fostream)); 


        out.write("&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;");
        out.write("&lt;CBB&gt;");

        // Printing out the filenames for the SodaSystem
        for(File fileName : filesList)
        {


            if (fileName.isDirectory() &amp;&amp; fileName.getName().endsWith("vardeps"))
            {
                out.write("\t&lt;CSV CommonKey = " + "\"" + fileName.getName().substring(0, 3) +  "\"" +  "&gt;\n");

            }
            else
            {
               out.println("\t&lt;SV_File CommonKey = " + "\"" + fileName.getName().substring(0, (fileName.getName().length() - 4)) +  "\"" +  "&gt;\n");


               // This holds the filename for the Relation CommonKey
               filesListTrim = fileName.getName().substring(0, (fileName.getName().length() - 4));

                 // Open the file that is the first 
                 // command line parameter
                    FileInputStream fstream = new FileInputStream(fileName);

                    // Get the object of DataInputStream
                    DataInputStream in = new DataInputStream(fstream);
                    BufferedReader br = new BufferedReader(new InputStreamReader(in));
                    String strLine;

                    //Read File Line By Line
                    while ((strLine = br.readLine()) != null)   
                    {

                       // Print the SodaVariable Entity. 
                       out.println("\t&lt;SV CommonKey = " + "\"" + strLine +  "\"" +  "/&gt;");



                       // Print the SodaVariableDependency RelationTable.

                       out.println("\t&lt;SV_Depend DependentVariableID = " + "\"" + filesListTrim +  "\" SourceVariableID = " + "\"" + strLine +  "\"" +  "/&gt;");

                       intID ++;
                      }
                    out.write("\n\t&lt;/SV&gt;\n");
                      //Close the input stream
                      in.close();                    
            }
            //out.println("/&gt;");
            intID ++;
            out.write("\n\t&lt;/SodaSystem&gt;\n");
        }
    }

       out.println("\n&lt;/CBB&gt;"); 
       out.flush();             
       out.close(); 
    }
    catch(Exception E) {
         E.printStackTrace();
    }
} 
}
</code></pre>

<p>Issue faced : the format is not proper which i am expeccting.</p>
