title: Error while parsing XML in R
body: <p>I have some XML data which is as follows:</p>
  
  <pre><code>&lt;?xml version=1.0 encoding=UTF-8?&gt;
  &lt;tasks xml=xyz.com/abc/wkbh/task&gt;
  &lt;task&gt;
  &lt;taskxml&gt;
  &lt;Claim prDocumentIdentifier=137####_##62###&gt;
  &lt;ClaimNumber&gt;13####_##62###&lt;/ClaimNumber&gt;
  &lt;FreeTextDescription&gt;INS PASSENGER IN UNINSURED AUTOMOBILE THAT VEERED OFF THE RD INTO A DITCH&lt;/FreeTextDescription&gt;
  &lt;ClaimCauses&gt;
  &lt;ClaimCause&gt;
  &lt;ActualValue&gt;THIRD PARTY STRUCK INSURED'S PARKED VEHICLE&lt;/ActualValue&gt;
  &lt;Category&gt;MOTOR_ACCIDENT_TP_HIT_FP&lt;/Category&gt;
  &lt;/ClaimCause&gt;
  &lt;/ClaimCauses&gt;
  &lt;IncidentDate&gt;2006-10-13&lt;/IncidentDate&gt;
  &lt;IncidentTime&gt;14:30:00.000&lt;/IncidentTime&gt;
  &lt;ReportedDate&gt;2008-01-28&lt;/ReportedDate&gt;
  &lt;ReportedTime&gt;13:14:00.000&lt;/ReportedTime&gt;
  &lt;ClosureDate&gt;2014-06-25&lt;/ClosureDate&gt;
  &lt;PolicyHolderDrivingAnotherVehicleFlag&gt;N&lt;/PolicyHolderDrivingAnotherVehicleFlag&gt;
  &lt;UnusualCircumstancesFlag&gt;N&lt;/UnusualCircumstancesFlag&gt;
  &lt;LiableParties&gt;
  &lt;ActualValue&gt;DRIVER NOT AT FAULT&lt;/ActualValue&gt;
  &lt;/LiableParties&gt;
  &lt;ClaimType&gt;
  &lt;Category&gt;PERSONAL_MOTOR&lt;/Category&gt;
  &lt;/ClaimType&gt;
  &lt;ClaimStatus&gt;
  &lt;ActualValue&gt;OPEN&lt;/ActualValue&gt;
  &lt;Category&gt;OPEN&lt;/Category&gt;
  &lt;/ClaimStatus&gt;
  &lt;CloseReason&gt;
  &lt;ActualValue&gt;PAID&lt;/ActualValue&gt;
  &lt;Category&gt;SETTLED&lt;/Category&gt;
  &lt;/CloseReason&gt;
  &lt;ClaimReportedBy&gt;
  &lt;ActualValue&gt;OTHER&lt;/ActualValue&gt;
  &lt;/ClaimReportedBy&gt;
  &lt;SupportingInformation&gt;
  &lt;AuthoritiesNotifiedOrAtScene&gt;N&lt;/AuthoritiesNotifiedOrAtScene&gt;
  &lt;UnusualCircumstances&gt;N&lt;/UnusualCircumstances&gt;
  &lt;/SupportingInformation&gt;
  &lt;ClaimSites&gt;
  &lt;ClaimSite&gt;
  &lt;IsOccupiedFlag&gt;Y&lt;/IsOccupiedFlag&gt;
  &lt;/ClaimSite&gt;
  &lt;/ClaimSites&gt;
  &lt;MotorClaimVehicles&gt;
  &lt;MotorClaimVehicle&gt;
  &lt;ID&gt;104####_137####&lt;/ID&gt;
  &lt;MotorClaimVehicleRole&gt;
  &lt;ActualValue&gt;POLICY_HOLDER_VEHICLE&lt;/ActualValue&gt;
  &lt;Category&gt;POLICY_HOLDER_VEHICLE&lt;/Category&gt;
  &lt;/MotorClaimVehicleRole&gt;
  &lt;Make&gt;FORD&lt;/Make&gt;
  &lt;ManufactureYear&gt;2002&lt;/ManufactureYear&gt;
  &lt;Model&gt;FOCUS SE WAGON&lt;/Model&gt;
  &lt;Status&gt;
  &lt;Category&gt;ACTIVE&lt;/Category&gt;
  &lt;/Status&gt;
  &lt;TotalDistanceTravelled&gt;
  &lt;Units&gt;KM&lt;/Units&gt;
  &lt;Amount&gt;0&lt;/Amount&gt;
  &lt;/TotalDistanceTravelled&gt;
  &lt;OwnershipStatus&gt;
  &lt;ActualValue&gt;OWNED&lt;/ActualValue&gt;
  &lt;Category&gt;OWNED&lt;/Category&gt;
  &lt;/OwnershipStatus&gt;
  &lt;/MotorClaimVehicle&gt;
  &lt;/MotorClaimVehicles&gt;
  &lt;/Claim&gt;
  &lt;/taskxml&gt;
  &lt;/task&gt;
  &lt;/tasks&gt;
  </code></pre>
  
  <p>I'm trying to extract the columns ClaimNumber, FreeTextDescription and others into a data frame. When I'm trying to parse the data using XML package </p>
  
  <pre><code>xml_df_task &lt;- xmlParse("xyz.xml")
  </code></pre>
  
  <p>I'm getting the following error:</p>
  
  <pre><code>Error: 1: String not started expecting ' or "
  2: Malformed declaration expecting version
  3: Blank needed here
  4: parsing XML declaration: '?&gt;' expected
  5: AttValue: " or ' expected
  6: attributes construct error
  7: Couldn't find end of Start Tag tasks line 1
  8: Extra content at the end of the document
  </code></pre>
  
  <p>I am new to XML related packages. So any help around this error is highly appreciated.</p>
  
  <p>P.S. This is only a small snippet of an actual column.</p>
  
  <p><strong>Edit:</strong> The XML is a valid one but it is embedded in some of the columns of the data which is in text format. When I'm trying to read the text data in R and convert to data frame using the code:</p>
  
  <pre><code>fpath &lt;- "pathofdata.txt"
  dat &lt;- read.table(fpath, header = T, sep = "|", fill = T)
  </code></pre>
  
  <p>I'm getting a data frame but the XML content is becoming invalid as some of the quotes are vanishing. So, trying to parse it as a seperate XML after the data frame step is not working out.</p>
  
  <p>An updated snippet of the data:</p>
  
  <pre><code>H|TASK_ID|TASK_REFERENCE|TASK_NAME|TASK_TYPE|TASK_RAISED_TS|TASK_STATE|TASK_VIEWED_FLAG|TASK_OUTCOME|CURRENT_QUEUE|QUEUE_CHANGE_TS|**TASK_XML_DATA**|**SCORE_XML_DATA**|
  |"12"|"137####_##62###"|"137####_##62###"|"Claim"|"14APR2015:23:36:04"|"AwaitingTriageEast"|"N"|" "|"4"|"."|"&lt;?xml version="1.0" encoding="UTF-8"?&gt;&lt;tasks xmlns="xyz.com/abc/wkbh/task"&gt;
  </code></pre>
  
  <p>.....
  (same as above)</p>
  
  <p>Any help on this error would save my day.</p>