title: PHP Read and Parse XML like File
body: <p>We are indexing our journals with PHP. We have journal meta data files. I am trying to parse it with PHP SimpleXML but i am getting lots of errors.</p>
  
  <blockquote>
    <p>Warning: simplexml_load_string(): Entity: line 19: parser error :
    Opening and ending tag mismatch: XUI line 19 and BB in *** on line 62</p>
    
    <p>Warning: simplexml_load_string(): s;S PERSPECTIVE
    
    <p>Warning: simplexml_load_string(): ^ in *** on line 62</p>
    
    <p>Warning: simplexml_load_string(): Entity: line 44: parser error :
    Opening and ending tag mismatch: BB line 4 and D in *** on line 62</p>
    
    <p>Warning: simplexml_load_string(): 33rd ed. St. Louis, MO: Elsevier
    Health Sciences; 2016.
    
    <p>Warning: simplexml_load_string(): ^ in *** on line 62</p>
    
    <p>Warning: simplexml_load_string(): Entity: line 61: parser error :
    Opening and ending tag mismatch: XUI line 61 and BB in *** on line 62</p>
    
    <p>Warning: simplexml_load_string(): R TO THE EDITOR
    
    <p>Warning: simplexml_load_string(): ^ in *** on line 62</p>
    
    <p>Warning: simplexml_load_string(): Entity: line 74: parser error :
    Opening and ending tag mismatch: BB line 46 and D in *** on line 62</p>
  </blockquote>
  
  <p>When i looked at the file it seems like an XML file. How can i parse it with PHP?.</p>
  
  <p>The code i am using is:</p>
  
  <pre><code>$file = file_get_contents('xyz.0');
  
  $file = utf8_decode($file);
  $file = str_replace("&amp;", "", $file); //For problems with &amp; character
  
  //libxml_use_internal_errors(true);
  $xml = simplexml_load_string($file, 'SimpleXMLElement', LIBXML_NOCDATA);
  </code></pre>
  
  <p>Sample XML Code from file:</p>
  
  <pre><code>&lt;!DOCTYPE dg SYSTEM "ovidbase.dtd"&gt; &lt;DG&gt;&lt;COVER NAME="G1893697-201804000-00000"&gt; &lt;D AN="01893697-201804000-00001" V="2009.2F" FILE="G1893697-201804000-00001"&gt; &lt;BB&gt; &lt;TG&gt; &lt;TI&gt;Oh Blood Pressure Measurements&amp;mdash;Where Art Thou&amp;quest;&lt;/TI&gt;&lt;/TG&gt; &lt;BY&gt; &lt;PN&gt;&lt;FN&gt;G.&lt;/FN&gt;&lt;MN&gt;Stephen&lt;/MN&gt;&lt;SN&gt;Morris&lt;/SN&gt;&lt;DEG&gt;PT, PhD, FACSM&lt;/DEG&gt;&lt;/PN&gt; &lt;AF&gt;&lt;P&gt;President, Oncology Section of the APTA; and Professor, Department of Physical Therapy, Wingate University, Wingate, NC&lt;/P&gt;&lt;/AF&gt; &lt;BT&gt;&lt;P&gt;&lt;E T="B"&gt;Correspondence:&lt;/E&gt; G. Stephen Morris, PT, PhD, FACSM, Department of Physical Therapy, Wingate University, 215 N. Camden Rd, Wingate, NC 28174 (&lt;URL&gt;s.morris&amp;commat;wingate.edu&lt;/URL&gt;).&lt;/P&gt;&lt;P&gt;The author declares no conflicts of interest.&lt;/P&gt;&lt;/BT&gt;&lt;/BY&gt; &lt;SO&gt; &lt;PB&gt;Rehabilitation Oncology&lt;/PB&gt; &lt;ISN&gt;2168-3808&lt;/ISN&gt; &lt;DA&gt;&lt;MO&gt;April&lt;/MO&gt;&lt;YR&gt;2018&lt;/YR&gt;&lt;/DA&gt; &lt;V&gt;36&lt;/V&gt; &lt;IS&gt;&lt;IP&gt;2&lt;/IP&gt;&lt;/IS&gt; &lt;PG&gt;79&amp;ndash;80&lt;/PG&gt;&lt;/SO&gt; &lt;CP&gt;&amp;copy; 2018 Oncology Section, APTA.&lt;/CP&gt; &lt;DT&gt;PRESIDENT&amp;apos;S PERSPECTIVE&lt;/DT&gt;&lt;XUI XDB="pub-doi" UI="10.1097/01.REO.0000000000000118"&gt;&lt;/BB&gt; &lt;BD&gt; &lt;LV1&gt;&lt;HD&gt;&amp;NA;&lt;/HD&gt; &lt;P&gt;physical therapy&amp;quest;&lt;/P&gt;&lt;/LV1&gt; &lt;LV1&gt;&lt;SG&gt;&lt;SGN&gt;G. Stephen Morris, PT, PhD, FACSM&lt;/SGN&gt;&lt;/SG&gt;&lt;/LV1&gt;&lt;/BD&gt; &lt;ED&gt; &lt;EDS&gt;&lt;HD&gt;REFERENCES&lt;/HD&gt; &lt;RF ID="R1-1"&gt;1. &lt;JRF&gt;&lt;DRF&gt;Arena SK, Reyes A, Rolf M. Behaviors, and knowledge of outpatient physical therapists. Cardiopulm Phys Ther J. 2018;9:3&amp;ndash;12.&lt;/DRF&gt;&lt;PN&gt;&lt;FN&gt;SK&lt;/FN&gt;&lt;SN&gt;Arena&lt;/SN&gt;&lt;/PN&gt;&lt;PN&gt;&lt;FN&gt;A&lt;/FN&gt;&lt;SN&gt;Reyes&lt;/SN&gt;&lt;/PN&gt;&lt;PN&gt;&lt;FN&gt;M&lt;/FN&gt;&lt;SN&gt;Rolf&lt;/SN&gt;&lt;/PN&gt;&lt;TI&gt;Behaviors, and knowledge of outpatient physical therapists&lt;/TI&gt;&lt;PB&gt;Cardiopulm Phys Ther J&lt;/PB&gt;&lt;DA&gt;&lt;YR&gt;2018&lt;/YR&gt;&lt;/DA&gt;&lt;V&gt;9&lt;/V&gt;&lt;PG&gt;3&amp;ndash;12&lt;/PG&gt;&lt;/JRF&gt;&lt;/RF&gt; &lt;RF ID="R2-1"&gt;2. &lt;URF&gt;US Preventative Services Task Force. High blood pressure in adults: screening. https:&amp;sol;&amp;sol;www.uspreventiveservicestaskforce.org&amp;sol;Page&amp;sol;Document&amp;sol;RecommendationStatementFinal&amp;sol;high-blood-pressure-in-adults-screening. Accessed January 12, 2018.&lt;/URF&gt;&lt;/RF&gt; &lt;RF ID="R3-1"&gt;3. &lt;URF&gt;Centers for Disease Control and Prevention. High blood pressure fact sheet. https:&amp;sol;&amp;sol;www.cdc.gov&amp;sol;bloodpressure&amp;sol;facts.htm. Accessed January 12, 2018.&lt;/URF&gt;&lt;/RF&gt; &lt;RF ID="R4-1"&gt;4. &lt;JRF&gt;&lt;DRF&gt;Lein DH Jr, Clark D, Graham C, Perez P, Morris D. A model to integrate health promotion and wellness in physical therapist practice: development and validation. Phys Ther. 2017;97(12):1169&amp;ndash;1181.&lt;/DRF&gt;&lt;PN&gt;&lt;FN&gt;DH&lt;/FN&gt;&lt;SN&gt;Lein&lt;/SN&gt;&lt;/PN&gt;&lt;PN&gt;&lt;FN&gt;D&lt;/FN&gt;&lt;SN&gt;Clark&lt;/SN&gt;&lt;/PN&gt;&lt;PN&gt;&lt;FN&gt;C&lt;/FN&gt;&lt;SN&gt;Graham&lt;/SN&gt;&lt;/PN&gt;&lt;PN&gt;&lt;FN&gt;P&lt;/FN&gt;&lt;SN&gt;Perez&lt;/SN&gt;&lt;/PN&gt;&lt;PN&gt;&lt;FN&gt;D&lt;/FN&gt;&lt;SN&gt;Morris&lt;/SN&gt;&lt;/PN&gt;&lt;TI&gt;A model to integrate health promotion and wellness in physical therapist practice: development and validation&lt;/TI&gt;&lt;PB&gt;Phys Ther&lt;/PB&gt;&lt;DA&gt;&lt;YR&gt;2017&lt;/YR&gt;&lt;/DA&gt;&lt;V&gt;97&lt;/V&gt;&lt;PG&gt;1169&amp;ndash;1181&lt;/PG&gt;&lt;/JRF&gt;&lt;/RF&gt; &lt;RF ID="R5-1"&gt;5. &lt;URF&gt;Riebe D, ed. ACSM&amp;apos;s Guidelines for Exercise Testing and Prescription. 10th ed. Baltimore, Maryland: Wolters Kluwer; 2018.&lt;/URF&gt;&lt;/RF&gt; &lt;RF ID="R6-1"&gt;6. &lt;JRF&gt;&lt;DRF&gt;Pickering TG, Hall JE, Appel LJ, et al Recommendations for blood pressure measurement in humans and experimental animals: part 1: blood pressure measurement in humans: a statement for professionals from the Subcommittee of Professional and Public Education of the American Heart Association Council on High Blood Pressure Research. Circulation. 2005;111(5):697&amp;ndash;716.&lt;/DRF&gt;&lt;PN&gt;&lt;FN&gt;TG&lt;/FN&gt;&lt;SN&gt;Pickering&lt;/SN&gt;&lt;/PN&gt;&lt;PN&gt;&lt;FN&gt;JE&lt;/FN&gt;&lt;SN&gt;Hall&lt;/SN&gt;&lt;/PN&gt;&lt;PN&gt;&lt;FN&gt;LJ&lt;/FN&gt;&lt;SN&gt;Appel&lt;/SN&gt;&lt;/PN&gt;&lt;TI&gt;Recommendations for blood pressure measurement in humans and experimental animals: part 1: blood pressure measurement in humans: a statement for professionals from the Subcommittee of Professional and Public Education of the American Heart Association Council on High Blood Pressure Research&lt;/TI&gt;&lt;PB&gt;Circulation&lt;/PB&gt;&lt;DA&gt;&lt;YR&gt;2005&lt;/YR&gt;&lt;/DA&gt;&lt;V&gt;111&lt;/V&gt;&lt;PG&gt;697&amp;ndash;716&lt;/PG&gt;&lt;/JRF&gt;&lt;/RF&gt; &lt;RF ID="R7-1"&gt;7. &lt;JRF&gt;&lt;DRF&gt;Rabbia F, Testa E, Rabbia S, et al Effectiveness of blood pressure educational and evaluation program for the improvement of measurement accuracy among nurses. High Blood Press Cardiovasc Prev. 2013;20(2):77&amp;ndash;80.&lt;/DRF&gt;&lt;PN&gt;&lt;FN&gt;F&lt;/FN&gt;&lt;SN&gt;Rabbia&lt;/SN&gt;&lt;/PN&gt;&lt;PN&gt;&lt;FN&gt;E&lt;/FN&gt;&lt;SN&gt;Testa&lt;/SN&gt;&lt;/PN&gt;&lt;PN&gt;&lt;FN&gt;S&lt;/FN&gt;&lt;SN&gt;Rabbia&lt;/SN&gt;&lt;/PN&gt;&lt;TI&gt;Effectiveness of blood pressure educational and evaluation program for the improvement of measurement accuracy among nurses&lt;/TI&gt;&lt;PB&gt;High Blood Press Cardiovasc Prev&lt;/PB&gt;&lt;DA&gt;&lt;YR&gt;2013&lt;/YR&gt;&lt;/DA&gt;&lt;V&gt;20&lt;/V&gt;&lt;PG&gt;77&amp;ndash;80&lt;/PG&gt;&lt;/JRF&gt;&lt;/RF&gt; &lt;RF ID="R8-1"&gt;8. &lt;JRF&gt;&lt;DRF&gt;Frese EM, Richter RR, Burlis TV. Self-reported measurement of heart rate and blood pressure in patients by physical therapy clinical instructors. Phys Ther. 2002;82(12):1192&amp;ndash;1200.&lt;/DRF&gt;&lt;PN&gt;&lt;FN&gt;EM&lt;/FN&gt;&lt;SN&gt;Frese&lt;/SN&gt;&lt;/PN&gt;&lt;PN&gt;&lt;FN&gt;RR&lt;/FN&gt;&lt;SN&gt;Richter&lt;/SN&gt;&lt;/PN&gt;&lt;PN&gt;&lt;FN&gt;TV&lt;/FN&gt;&lt;SN&gt;Burlis&lt;/SN&gt;&lt;/PN&gt;&lt;TI&gt;Self-reported measurement of heart rate and blood pressure in patients by physical therapy clinical instructors&lt;/TI&gt;&lt;PB&gt;Phys Ther&lt;/PB&gt;&lt;DA&gt;&lt;YR&gt;2002&lt;/YR&gt;&lt;/DA&gt;&lt;V&gt;82&lt;/V&gt;&lt;PG&gt;1192&amp;ndash;1200&lt;/PG&gt;&lt;/JRF&gt;&lt;/RF&gt; &lt;RF ID="R9-1"&gt;9. &lt;JRF&gt;&lt;DRF&gt;Mouhavar E, Salahudeen A, Yeh ETH. Hypertension in cancer patients. Tex Heart Inst J. 2011;38(3):263&amp;ndash;265.&lt;/DRF&gt;&lt;PN&gt;&lt;FN&gt;E&lt;/FN&gt;&lt;SN&gt;Mouhavar&lt;/SN&gt;&lt;/PN&gt;&lt;PN&gt;&lt;FN&gt;A&lt;/FN&gt;&lt;SN&gt;Salahudeen&lt;/SN&gt;&lt;/PN&gt;&lt;PN&gt;&lt;FN&gt;ETH&lt;/FN&gt;&lt;SN&gt;Yeh&lt;/SN&gt;&lt;/PN&gt;&lt;TI&gt;Hypertension in cancer patients&lt;/TI&gt;&lt;PB&gt;Tex Heart Inst J&lt;/PB&gt;&lt;DA&gt;&lt;YR&gt;2011&lt;/YR&gt;&lt;/DA&gt;&lt;V&gt;38&lt;/V&gt;&lt;PG&gt;263&amp;ndash;265&lt;/PG&gt;&lt;/JRF&gt;&lt;/RF&gt; &lt;RF ID="R10-1"&gt;10. &lt;URF&gt;Gahart BL, Nazareno AR, eds. Intravenous Medications: A Handbook for Nurses and Health Professionals. 33rd ed. St. Louis, MO: Elsevier Health Sciences;
  2016.&lt;/URF&gt;&lt;/RF&gt;&lt;/EDS&gt;&lt;/ED&gt;&lt;/D&gt; &lt;D AN="01893697-201804000-00002" V="2009.2F" FILE="G1893697-201804000-00002"&gt; &lt;BB&gt; &lt;TG&gt; &lt;TI&gt;In 2018 &amp;ldquo;Spring Is the Time of Plans and Projects&amp;rdquo;&lt;/TI&gt;&lt;/TG&gt; &lt;BY&gt; &lt;PN&gt;&lt;FN&gt;Lucinda&lt;/FN&gt;&lt;MN&gt;(Cindy)&lt;/MN&gt;&lt;SN&gt;Pfalzer&lt;/SN&gt;&lt;DEG&gt;PT, PhD, FACSM, FAPTA&lt;/DEG&gt;&lt;/PN&gt; &lt;AF&gt;&lt;P&gt;Editor of &lt;E T="I"&gt;Oncology Rehabilitation&lt;/E&gt; and Emeriti Professor, Physical Therapy Department, University of Michigan-Flint, Flint, MI&lt;/P&gt;&lt;/AF&gt; &lt;BT&gt;&lt;P&gt;&lt;E T="B"&gt;Correspondence:&lt;/E&gt; Lucinda (Cindy) Pfalzer, PT, PhD, FACSM, FAPTA, Physical Therapy Department, University of Michigan-Flint, 2157 WSW Bldg, Flint, MI 48502 (&lt;URL&gt;cpfalzer&amp;commat;umich.edu&lt;/URL&gt;).&lt;/P&gt;&lt;P&gt;The author declares no conflicts of interest.&lt;/P&gt;&lt;/BT&gt;&lt;/BY&gt; &lt;SO&gt; &lt;PB&gt;Rehabilitation Oncology&lt;/PB&gt; &lt;ISN&gt;2168-3808&lt;/ISN&gt; &lt;DA&gt;&lt;MO&gt;April&lt;/MO&gt;&lt;YR&gt;2018&lt;/YR&gt;&lt;/DA&gt; &lt;V&gt;36&lt;/V&gt; &lt;IS&gt;&lt;IP&gt;2&lt;/IP&gt;&lt;/IS&gt; &lt;PG&gt;81&amp;ndash;82&lt;/PG&gt;&lt;/SO&gt; &lt;CP&gt;&amp;copy; 2018 Oncology Section, APTA.&lt;/CP&gt; &lt;DT&gt;LETTER TO THE EDITOR&lt;/DT&gt;&lt;XUI XDB="pub-doi" UI="10.1097/01.REO.0000000000000119"&gt;&lt;/BB&gt; &lt;BD&gt;
  </code></pre>
  
  <p>You can download the xml file from <a href="https://mega.nz/#!qTxHwaSY!-0vXEAdGasOT3DhiL9Ap3PQRQOPIucC-Uj14JAf3kcA" rel="nofollow noreferrer">here</a>.</p>
  
  <p>Thank you</p>
  
  <p>EDIT: This is different from the question <a href="https://stackoverflow.com/questions/3805050">XML parser error: entity not defined</a> This files are generated years ago (2000s etc.). I am not generating this files, i only try to parse them and get the meta data.</p>
  
  <p>EDIT 2: Sorry i am also trying to parse with Dom Parser and added the errors from it when i created the post. Now i added the SimpleXML errors.</p>