title: Run XPath over an XPath result within a Foreach loop
body: <p>I'm working on a project that reads datafeeds like these:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;producten&gt;
    &lt;product&gt;
      &lt;sku&gt;&lt;![CDATA[75100192B]]&gt;&lt;/sku&gt;
      &lt;price&gt;&lt;![CDATA[349.00]]&gt;&lt;/price&gt;
      &lt;old_price&gt;&lt;![CDATA[499.00]]&gt;&lt;/old_price&gt;
      &lt;in_stock&gt;&lt;![CDATA[1]]&gt;&lt;/in_stock&gt;
      &lt;delivery_time&gt;&lt;![CDATA[1 - 2 werkdagen]]&gt;&lt;/delivery_time&gt;
      &lt;manufacturer&gt;&lt;![CDATA[Kids River]]&gt;&lt;/manufacturer&gt;
      &lt;name&gt;&lt;![CDATA[Kids River Urban Stroller 3 in 1 Black / Grey  Black Frame]]&gt;&lt;/name&gt;
      &lt;description&gt;&lt;![CDATA[KidsRiver Urban Stroller]]&gt;&lt;/description&gt;
      &lt;url&gt;&lt;![CDATA[http://www.url.com/]]&gt;&lt;/url&gt;
      &lt;categorie&gt;&lt;![CDATA[Kinderwagens]]&gt;&lt;/categorie&gt;
      &lt;subcategorie&gt;&lt;![CDATA[Kinderwagen]]&gt;&lt;/subcategorie&gt;
      &lt;model&gt;&lt;![CDATA[Kids River Urban]]&gt;&lt;/model&gt;
      &lt;collectiejaar&gt;&lt;![CDATA[2011]]&gt;&lt;/collectiejaar&gt;
      &lt;shipping_price&gt;&lt;![CDATA[0.00]]&gt;&lt;/shipping_price&gt;
      &lt;image&gt;&lt;![CDATA[http://www.url.com/image.jpg]]&gt;&lt;/image&gt;
    &lt;/product&gt;
    &lt;product&gt;
      &lt;sku&gt;&lt;![CDATA[Joolz Day Silver / Black - 2012]]&gt;&lt;/sku&gt;
      &lt;price&gt;&lt;![CDATA[849.00]]&gt;&lt;/price&gt;
      &lt;old_price&gt;&lt;![CDATA[879.00]]&gt;&lt;/old_price&gt;
      &lt;in_stock&gt;&lt;![CDATA[1]]&gt;&lt;/in_stock&gt;
      &lt;delivery_time&gt;&lt;![CDATA[1 - 2 werkdagen]]&gt;&lt;/delivery_time&gt;
      &lt;manufacturer&gt;&lt;![CDATA[Joolz]]&gt;&lt;/manufacturer&gt;
      &lt;name&gt;&lt;![CDATA[Joolz Day Silver / Black]]&gt;&lt;/name&gt;
      &lt;description&gt;&lt;![CDATA[Joolz Day Compleet.]]&gt;&lt;/description&gt;
      &lt;url&gt;&lt;![CDATA[http://www.url.com/]]&gt;&lt;/url&gt;
      &lt;categorie&gt;&lt;![CDATA[Kinderwagens]]&gt;&lt;/categorie&gt;
      &lt;subcategorie&gt;&lt;![CDATA[Kinderwagen]]&gt;&lt;/subcategorie&gt;
      &lt;model&gt;&lt;![CDATA[Joolz Day]]&gt;&lt;/model&gt;
      &lt;collectiejaar&gt;&lt;![CDATA[2012]]&gt;&lt;/collectiejaar&gt;
      &lt;shipping_price&gt;&lt;![CDATA[0.00]]&gt;&lt;/shipping_price&gt;
      &lt;image&gt;&lt;![CDATA[http://www.url.com/image.jpg]]&gt;&lt;/image&gt;
    &lt;/product&gt;
  &lt;/producten&gt;
  </code></pre>
  
  <p>What I want to do it to make a loop that can read individual products from this feed so I made something like this:</p>
  
  <pre><code>// Spin up the SimpleXML parser
  $xml_feed = new SimpleXMLElement($feed_data);
  
  $products = $xml_feed-&gt;xpath('//producten/product');
  
  foreach ($products as $product)
  {
      $name = $product-&gt;xpath('./name');
      $price = $product-&gt;xpath('price');
      $old_price = $product-&gt;xpath('old_price');
      $in_stock = $product-&gt;xpath('in_stock');
      $manufacturer = $product-&gt;xpath('manufacturer');
  
      echo print_r( $name);
      echo var_dump((string) $price[0]);
      echo var_dump((string) $old_price[0]);
      echo var_dump((string) $in_stock[0]);
      echo var_dump((string) $manufacturer[0]);
      echo "\r\n";
  }
  </code></pre>
  
  <p>I was wondering if there is a better way to read a xml when using XPath 2 times. One before the loop and the other XPath within the loop. I'm doing it this way because I want to be able to parse all kinds of feeds.</p>
  
  <p>I'm a little concerned about the [0] behind the field: $price[0].</p>