title: Error reading in XML file for special character parsing
body: <p>I am currently reading through a folder of static XML files (thousands of them).</p>
  
  <p>Most of them were formatted correctly, but there are some special characters that I'd like to mask. As an example, one XML file has the invalid XML code as shown below:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
      &lt;INQUIRY version="4.0"&gt;
          &lt;AUTHENTICATION&gt;
              &lt;LICENSEKEY&gt;XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&lt;/LICENSEKEY&gt; 
              &lt;PASSWORD&gt;YYYYYYYYYYY&lt;/PASSWORD&gt; 
          &lt;/AUTHENTICATION&gt;
          &lt;QUERY&gt;
              &lt;TRACKID&gt;1-1-1&lt;/TRACKID&gt; 
              &lt;TYPE&gt;VALID&lt;/TYPE&gt;
              &lt;CHANNEL&gt;INTERNET&lt;/CHANNEL&gt;
              &lt;INQUIRYTYPE&gt;O&lt;/INQUIRYTYPE&gt;
              &lt;DATA&gt;
                  &lt;NAME&gt;BARNES &amp; NOBLE&lt;/NAME&gt;
              &lt;/DATA&gt;
          &lt;/QUERY&gt;
      &lt;/INQUIRY&gt;
  </code></pre>
  
  <p>I attempt to swap out the &amp; with the code:</p>
  
  <pre><code>install.packages("XML")
  library(XML)
  
  location &lt;- "C:/Users/Desktop/temp"
  filenames=dir(location)
  
  for (i in 1:length(filenames)){
     tmp &lt;- gsub("&amp;", "&amp;amp;", readLines(paste0(location,"/",filenames[i])))
     data &lt;- xmlParse(tmp)
     TMP&lt;-xmlToDataFrame(nodes=getNodeSet(data,"//DATA"))
     DATAX_DF&lt;-rbind(TMP,DATAX_DF)
  }
  </code></pre>
  
  <p>Resulting in the following:</p>
  
  <pre><code>Warning message:
  In readLines(paste0(location, "/", filenames[i])) :
    incomplete final line found on 'C:/Users/Desktop/tmp/1-1-1_req.XML'
  </code></pre>
  
  <p>What is another work around to replace the ampersand and/or any ideas on why it reads the final line as incomplete so that I don't receive warnings?</p>