title: Parsing XML file with Laravel
body: <p>Ok, so I am pretty stuck on this. I have a semi-complex XML file which looks a bit like this:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  
  &lt;community ID="1234" POSTDATE="20180329" xmlns="" COMPANY="SAMPLE CO"&gt;
     &lt;data1&gt;
        &lt;datatype ID="0001"&gt;
           &lt;utpricing LT="1" STARTDATE="20150102" ENDDATE="20160102" BASEAMOUNT="99" CONCESSION="0.00" EFFAMOUNT="99" CONTYPE="SAMPLE" CONVALUE="0.00"/&gt;
        &lt;utpricing LT="1" STARTDATE="20150102" ENDDATE="20160102" BASEAMOUNT="99" CONCESSION="0.00" EFFAMOUNT="99" CONTYPE="SAMPLE" CONVALUE="0.00"/&gt;
        &lt;utpricing LT="1" STARTDATE="20150102" ENDDATE="20160102" BASEAMOUNT="99" CONCESSION="0.00" EFFAMOUNT="99" CONTYPE="SAMPLE" CONVALUE="0.00"/&gt;
        &lt;utpricing LT="1" STARTDATE="20150102" ENDDATE="20160102" BASEAMOUNT="99" CONCESSION="0.00" EFFAMOUNT="99" CONTYPE="SAMPLE" CONVALUE="0.00"/&gt;
  &lt;/data1&gt;
            &lt;datatype ID="0002"&gt;
               &lt;utpricing LT="2" STARTDATE="20160102" ENDDATE="20170102" BASEAMOUNT="99" CONCESSION="0.00" EFFAMOUNT="99" CONTYPE="SAMPLE" CONVALUE="0.00"/&gt;
            &lt;utpricing LT="1" STARTDATE="20150102" ENDDATE="20160102" BASEAMOUNT="99" CONCESSION="0.00" EFFAMOUNT="99" CONTYPE="SAMPLE" CONVALUE="0.00"/&gt;
            &lt;utpricing LT="1" STARTDATE="20150102" ENDDATE="20160102" BASEAMOUNT="99" CONCESSION="0.00" EFFAMOUNT="99" CONTYPE="SAMPLE" CONVALUE="0.00"/&gt;
            &lt;utpricing LT="1" STARTDATE="20150102" ENDDATE="20160102" BASEAMOUNT="99" CONCESSION="0.00" EFFAMOUNT="99" CONTYPE="SAMPLE" CONVALUE="0.00"/&gt;
      &lt;/datatype&gt;
  &lt;/data1&gt;
    &lt;data2&gt;
        &lt;data2 ID="141" NAME="IAM | 1 | 1.00" SQFTMIN="111" SQFTMAX="222"/&gt;
        &lt;data2 ID="142" NAME="ASA | 1 | 1.00" SQFTMIN="111" SQFTMAX="222"/&gt;
        &lt;data2 ID="143" NAME="MPL | 1 | 1.00" SQFTMIN="111" SQFTMAX="222"/&gt;
        &lt;data2 ID="144" NAME="EBI | 1 | 1.00" SQFTMIN="111" SQFTMAX="222"/&gt;
        &lt;data2 ID="145" NAME="TOF | 2 | 2.00" SQFTMIN="111" SQFTMAX="222"/&gt;
     &lt;/data2&gt;
  
     &lt;samples&gt;
        &lt;sample ID="001" AVAILDATE="20152901" STATUS="Unavailable" data1TYPE="001" UNITCAT="1X1" SOMEVALUE="50.00" data2ID="141"&gt;
           &lt;item1 ID="59" item2="50.00" DESCRIPTION="Sample Description"/&gt;
           &lt;offeredterm LT="2" BASEAMOUNT="1120.00" TOTALCONCESSION="0.00" EFFECTIVESAMPLE="1120.00" CONTYPE="T" CONVALUE="0.00"/&gt;
        &lt;/sample&gt;
      &lt;sample ID="002" AVAILDATE="20152901" STATUS="Unavailable" data1TYPE="001" UNITCAT="1X1" SOMEVALUE="50.00" data2ID="141"&gt;
           &lt;item1 ID="59" item2="50.00" DESCRIPTION="Sample Description"/&gt;
           &lt;offeredterm LT="2" BASEAMOUNT="1120.00" TOTALCONCESSION="0.00" EFFECTIVESAMPLE="1120.00" CONTYPE="T" CONVALUE="0.00"/&gt;
        &lt;/sample&gt;
  </code></pre>
  
  <p>So I have tried to parse this a few ways, but what I want to end up with is a structured collection that I can then run operations on like selecting all items from <code>data1</code> which have the same <code>data1TYPE</code> as the <code>datatype ID</code> etc. </p>
  
  <p>Currently my code looks like this:</p>
  
  <pre><code>$XML = Storage::disk('local')-&gt;get('data\XML.xml');
  $random = collect(json_decode(json_encode((array) simplexml_load_string($XML)), true));
  </code></pre>
  
  <p>I have been able to retrieve an object like this and then loop through by the indexes and build a separate collection for each xml tag. This doesn't feel that efficient though and I'm not sure how I would best run the comparison operations later on.</p>
  
  <p>Any ideas?</p>