title: How to frame XML from Excel (XSLX) using Java
body: <p>I am reading an excel (XSLX) file using Java in netbeans 7.0.
  I am able to read the excel sheet contents and print it to output too.</p>
  
  <p>Now I have to convert the excel data into XML file. The tags will be the column headers and each row goes into the corresponding tags.</p>
  
  <p>This is the input worksheet in a xslx file. The ID, Variable, desc and notes are the column headers.</p>
  
  <blockquote>
  <pre><code>ID          Variable     Desc     Notes
  B0001                    VSI_C  
  B0001           1        VSI_C_R    
  B0001           2        VSI_C_P    
  B0002                    VSI_C_L    
  B0003                    VSI_C_H    
  B0004                    VSI_C_O    
  </code></pre>
  </blockquote>
  
  <p>Now, I am converting this data into an XML file.
  The output I am expecting is,</p>
  
  <blockquote>
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;Bin_code&gt;
  &lt;DCT&gt;
      &lt;ID&gt;B0001&lt;/ID&gt;
      &lt;Variable/&gt;
      &lt;Desc&gt;VSI_C&lt;/Desc&gt;
      &lt;Notes/&gt;
  &lt;/DCT&gt;
  &lt;DCT&gt;
      &lt;ID&gt;B0001&lt;/ID&gt;
      &lt;Variable/&gt;
      &lt;Desc&gt;VSI_C_R&lt;/Desc&gt;
      &lt;Notes/&gt;
  &lt;/DCT&gt;
       ............
       ...............
  &lt;/Bin_code&gt;
  </code></pre>
  </blockquote>
  
  <p>I tried until this. I know i have to use 'sheet' object. But I am not sure, how to use this.</p>
  
  <blockquote>
    <p>import java.io.File;</p>
  </blockquote>
  
  <pre><code>import java.io.FileInputStream;
  import java.io.InputStream;
  import java.io.*;
  import org.apache.poi.ss.usermodel.Cell;
  import org.apache.poi.ss.usermodel. Row;
  import org.apache.poi.ss.usermodel.Sheet;
  import org.apache.poi.ss.usermodel.Workbook;
  import org.apache.poi.ss.usermodel.WorkbookFactory;
  
  public class XSLXReader {   
  public static void main(String[] args) 
  {   
      DataInputStream in = null;
      BufferedReader br = null;
      FileWriter fostream;
      FileWriter fostreamBatch;
      BufferedWriter out = null;
      BufferedWriter outBatch = null;
      String strOutputPath = "D:\\Proj\\Current_\\";
      String strFilePrefix = "Master 5.2-B";
      String strLine;
  
      try {           
      InputStream inputStream = new FileInputStream(new File("D:\\Proj\\Current_\\Master A-B.xlsx"));
      Workbook wb = WorkbookFactory.create(inputStream);            
      Sheet sheet = wb.getSheet("Bin-code");
  
      in = new DataInputStream(inputStream);
      br = new BufferedReader(new InputStreamReader(in));
  
      fostream = new FileWriter(strOutputPath+"\\"+strFilePrefix+".xml");
      out = new BufferedWriter(fostream);
  
      out.write("&lt;Bin-code&gt;");
  
      while ((strLine = br.readLine()) != null)
      {
          out.write("&lt;DCT&gt;");
          out.write("&lt;ID&gt;" + strLine.substring(1, strLine.length()) + "&lt;/ID&gt;");
  
          out.write("&lt;/DCT&gt;");
  
      }
      out.write("&lt;/Bin-code&gt;");
  } catch (Exception e) {         
      e.printStackTrace();        
  }   
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Please help me in framing out the input data in the xslx to the output data into xml as shown above.</p>
  
  <p>Thanks
  Ramm</p>