title: Get XML element by ID with PHP
body: <p>I'm having some difficulties getting PHP to read my XML document. I'm trying to echo the content from each  node based on whatever catid I've selected.</p>
  
  <p>XML: text.xml</p>
  
  <pre><code>&lt;root&gt;
    &lt;category catid='1'&gt;
      &lt;text id='TXT1'&gt;&lt;![CDATA[ Lorem Ipsum ]]&gt;&lt;/text&gt;
      &lt;text id='TXT2'&gt;&lt;![CDATA[ Lorem Ipsum ]]&gt;&lt;/text&gt;
      &lt;text id='TXT3'&gt;&lt;![CDATA[ Lorem Ipsum ]]&gt;&lt;/text&gt;
    &lt;/category&gt;
    &lt;category catid='2'&gt;
      &lt;text id='TXT1'&gt;&lt;![CDATA[ Lorem Ipsum ]]&gt;&lt;/text&gt;
      &lt;text id='TXT2'&gt;&lt;![CDATA[ Lorem Ipsum ]]&gt;&lt;/text&gt;
      &lt;text id='TXT3'&gt;&lt;![CDATA[ Lorem Ipsum ]]&gt;&lt;/text&gt;
    &lt;/category&gt;
  &lt;/root&gt;
  </code></pre>
  
  <p>PHP:</p>
  
  <pre><code>&lt;?php  
  $xml = simplexml_load_file('/path/to/text.xml');
  $category = $xml-&gt;xpath("//category[@catid='1']/text");
  $ids = ['TXT1', 'TXT2', 'TXT3'];
  
  foreach($ids as $id){
    echo $category[$id]; //I'm not quite sure how to do this bit.
  }
  ?&gt;
  </code></pre>
  
  <p>Any help is appreciated, thanks!</p>