title: Ruby - Reading and editing XML file
body: <p>I am writing a Ruby (1.9.3) script that reads XML files from a folder and then edit it if necessary.</p>
  
  <p>My issue is that I was given XML files converted by <a href="http://tidy.sourceforge.net/" rel="noreferrer">Tidy</a> but its ouput is a little strange, fo example:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;XML&gt;
    &lt;item&gt;
        &lt;ID&gt;000001&lt;/ID&gt;
        &lt;YEAR&gt;2013&lt;/YEAR&gt;
        &lt;SUPPLIER&gt;Supplier name test,
        Coproration&lt;/SUPPLIER&gt;
  ...
  </code></pre>
  
  <p>As you can see the  has and extra CRLF. I dont know why it has this behaviour but I am addressing it with a ruby script. But am having trouble as I need to see either if the last character of the line is "<strong>></strong>" or if the first is "<strong>&lt;</strong>" so that I can see if there is something wrong with the markup.</p>
  
  <p>I have tried:</p>
  
  <pre><code>Dir.glob("C:/testing/corrected/*.xml").each do |file|
  
  puts file
  
    File.open(file, 'r+').each_with_index do |line, index|
  
      first_char = line[0,1]
  
      if first_char != "&lt;"
          //copy this line to the previous line and delete this one?
      end
  
    end
  
  end
  </code></pre>
  
  <p>I also feel like I should be copying the original file content as I read it to another temporary file and then overwrite. Is that the best "way"? Any tips are welcome as I do not have much experience in altering a files content.</p>
  
  <p>Regards</p>