title: How to convert text file to xml file?
body: <p>Here is the situation, I have downloaded a text file from a server, it looks like this:</p>
  
  <pre><code>Home  
  Address  
  Suburb  
  State   
  Post Code       
  Latitude    
  Longitude   
  Phone    
  Fax   
  Curfew Hours Start  
  Curfew Hours End  
  Website
  
  FirstHome Address   
  "123 Street sd" 
  FirstHome Address   
  HMH  
  2223 "Addresss,dsdsd"   
  -54.000012  
  120.000000  
  (03) 1232 1242    
  (03) 1232 3244  
  Mon-Sun 10pm    
  "Mon-Sun 6am"   
  http:www.dsdsdsfirsthome.com
  
  2ndHome     
  2903 Building 1     
  2ndHome         
  2HMF     
  3875    "2nd Adddedere" 
  -00.00001   
  002.323232  
  (03) 2223 2323  
  (03) 1233 4343      
  http:dsdd
  
  asdsfadf.com
  </code></pre>
  
  <p>And Now I need to convert it to an XML File that should be like this:</p>
  
  <p><img src="https://i.stack.imgur.com/4wnhz.jpg" alt="enter image description here"></p>
  
  <p>Any Ideas?  thank you in advance.</p>
  
  <p>I used BufferedReader to read the textfile from the sdcard and StreamResult to write the XML file. And then executed this:</p>
  
  <pre><code>TransformerConfigurationException, SAXException {      
  SAXTransformerFactory tf = (SAXTransformerFactory) SAXTransformerFactory.newInstance();     
  th = tf.newTransformerHandler();   
  Transformer serializer = th.getTransformer();     
  serializer.setOutputProperty(OutputKeys.ENCODING, "ISO-8859-1");       serializer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");  serializer.setOutputProperty(OutputKeys.INDENT, "yes");        
  th.setResult(aStreamResult);    
  th.startDocument();     
  atts = new AttributesImpl();    
  th.startElement("", "", "Homes", atts);
  </code></pre>
  
  <p>after that, while loop is called:        </p>
  
  <pre><code>while ((aString = aBufferedReader.readLine()) != null){          
  process(word)          
  }  
  </code></pre>
  
  <p>The method process(word) is this:</p>
  
  <p>TransformerHandler th;
  AttributesImpl atts;</p>
  
  <pre><code>public void process(String s) throws SAXException {         
  String[] elements = s.split(" ");           
  atts.clear();         
  th.startElement("", "", "Home", atts);          
  th.startElement("", "", "1stHome", atts);          
  th.characters(elements[0].toCharArray(), 0, elements[0].length());         
  th.endElement("", "", "1stHome");              
  th.startElement("", "", "Address", atts);          
   th.characters(elements[0].toCharArray(), 0, elements[0].length());           
  th.endElement("", "", "Address");          
  th.endElement("", "", "Home");               
  }
  </code></pre>
  
  <p>After that just close the tags by calling closeXML();</p>
  
  <pre><code>public void closeXML() throws SAXException {            
  th.endElement("", "", "Homes");          
  th.endDocument();         
  }
  </code></pre>
  
  <p>The problem is that I read it line by line..</p>