title: text file to xml conversion java
body: <p>I have text file and I want to convert this in to a XML file in java:
  Read  the file in java and then convert in to xml.</p>
  
  <pre><code>Contact
  Arun_niit
  Arun_niit
  nura_e@yahoo.co.in
  Contact
  Contact
  Bống MũnHải
  Hải Anh Bống Mũn
  http://www.facebook.com/profile.php?id=689849077
  Contact
  </code></pre>
  
  <p>I want the output in the following order:</p>
  
  <pre><code>&lt;contact&gt;
  &lt;Firstname&gt;Arun_niit&lt;/Firstname&gt;
  &lt;Secondname&gt;Arun_niit&lt;/Secondname&gt;
  &lt;Email&gt;nura_e@yahoo.co.in&lt;/Email&gt;
  &lt;/contact&gt;
  &lt;contact&gt;
  &lt;Firstname&gt;Bống MũnHải&lt;/Firstname&gt;
  &lt;Secondname&gt;Hải Anh Bống Mũn&lt;/Secondname&gt;
  &lt;URL&gt;http://www.facebook.com/profile.php?id=689849077&lt;/URL&gt;
  &lt;/contact&gt;
  </code></pre>
  
  <p>Please help me guys &amp; sample codes will be highly appreciated.</p>
  
  <p>Is this correct way of doing it, please...
  [code]</p>
  
  <pre><code>  import java.io.*;
    import java.io.ObjectInputStream.GetField;
    import org.w3c.dom.*;
    import javax.xml.parsers.*;
    import javax.xml.transform.*;
    import javax.xml.transform.stream.*;
    import javax.xml.transform.dom.*;
    import java.util.Scanner;
  
  public class Item  {
  
  private String Name;
  private String LName;
  private String Email;
  public static void main (String args[]) {
  
  public static void readFile(File file)  
  {
  Scanner freader = new Scanner("D:/juin17.part");
  String line = null;
  while (freader.hasNextLine()) {
      line = freader.nextLine();
     if(line==contact){
  Item item = new item();
      item.Name =freader.nextLine();
      item.LName =freader.nextLine();
      item.Email =freader.nextLine();
      freader.nextLine();
      }
      itemList.add(item);
  }
  freader.close();  
    }
  
   FileOutputStream fos = new FileOutputStream(info.file);
   OutputFormat of = new OutputFormat("XML","windows-1250",true);
   of.setIndent(1);
   of.setIndenting(true);
   ContentHandler hd = serializer.asContentHandler();
   hd.startDocument();
   AttributesImpl atts = new AttributesImpl();
   hd.startElement("","",info.category,atts);
   for (int i=0;i&lt;itemList.size();i++)
  {
     atts.clear();
      Item temp = new Item();
      temp = itemList.get(i);
      hd.startElement("","","FirstName",atts);
      hd.characters(temp.Name.toCharArray(),0,temp.Name.length());
      hd.endElement("","","FirstName");
      hd.startElement("","","LastName",atts);
      hd.characters(temp.LName.toCharArray(),0,temp.LName.length());
      hd.endElement("","","LastName");
      hd.startElement("","","Email",atts);
      hd.characters(temp.mail.toCharArray(),0,temp.mail.length());
      hd.endElement("","","EMail");
   }
   hd.endElement("","",info.category);
   hd.endDocument();
   fos.close();
   }
   }
  </code></pre>