DOMXPath/cURL - Trying to get multiple elements into foreach loop
<p>I am parsing DOM elements from this page: <a href="http://www.sportsdirect.com/kappa-nulent-4-trainers-child-boys-039063?colcode=03906301" rel="nofollow">http://www.sportsdirect.com/kappa-nulent-4-trainers-child-boys-039063?colcode=03906301</a></p>

<p>Here is the specific DOM that i am focused right now:</p>

<pre><code>&lt;ul id="dnn_ctr103511_ViewTemplate_ctl00_ctl14_ulSizes" class="sizeButtons" data-clicktoselecttext="Click to select"&gt;

    &lt;li id="dnn_ctr103511_ViewTemplate_ctl00_ctl14_rptSizes_ctl00_liItem" role="radio" title="Click to select C10 (28)" data-text="C10 (28)" class="tooltip sizeButtonli "&gt;
        &lt;a href="DesktopModules/SportsDirect/ProductDetail/Controls/#" id="dnn_ctr103511_ViewTemplate_ctl00_ctl14_rptSizes_ctl00_ancLink"&gt;C10 (28)&lt;/a&gt;
    &lt;/li&gt;

    &lt;li id="dnn_ctr103511_ViewTemplate_ctl00_ctl14_rptSizes_ctl01_liItem" role="radio" title="Click to select C11 (29)" data-text="C11 (29)" class="tooltip sizeButtonli "&gt;
        &lt;a href="DesktopModules/SportsDirect/ProductDetail/Controls/#" id="dnn_ctr103511_ViewTemplate_ctl00_ctl14_rptSizes_ctl01_ancLink"&gt;C11 (29)&lt;/a&gt;
    &lt;/li&gt;

    &lt;li id="dnn_ctr103511_ViewTemplate_ctl00_ctl14_rptSizes_ctl02_liItem" role="radio" title="Click to select C12 (31)" data-text="C12 (31)" class="tooltip sizeButtonli "&gt;
        &lt;a href="DesktopModules/SportsDirect/ProductDetail/Controls/#" id="dnn_ctr103511_ViewTemplate_ctl00_ctl14_rptSizes_ctl02_ancLink"&gt;C12 (31)&lt;/a&gt;
    &lt;/li&gt;

    &lt;li id="dnn_ctr103511_ViewTemplate_ctl00_ctl14_rptSizes_ctl03_liItem" role="radio" title="Click to select C13 (32)" data-text="C13 (32)" class="tooltip sizeButtonli "&gt;
        &lt;a href="DesktopModules/SportsDirect/ProductDetail/Controls/#" id="dnn_ctr103511_ViewTemplate_ctl00_ctl14_rptSizes_ctl03_ancLink"&gt;C13 (32)&lt;/a&gt;
    &lt;/li&gt;

    &lt;li id="dnn_ctr103511_ViewTemplate_ctl00_ctl14_rptSizes_ctl04_liItem" role="radio" title="Click to select 1 (33)" data-text="1 (33)" class="tooltip sizeButtonli "&gt;
        &lt;a href="DesktopModules/SportsDirect/ProductDetail/Controls/#" id="dnn_ctr103511_ViewTemplate_ctl00_ctl14_rptSizes_ctl04_ancLink"&gt;1 (33)&lt;/a&gt;
    &lt;/li&gt;

    &lt;li id="dnn_ctr103511_ViewTemplate_ctl00_ctl14_rptSizes_ctl05_liItem" role="radio" title="Click to select 2 (34)" data-text="2 (34)" class="tooltip sizeButtonli "&gt;
        &lt;a href="DesktopModules/SportsDirect/ProductDetail/Controls/#" id="dnn_ctr103511_ViewTemplate_ctl00_ctl14_rptSizes_ctl05_ancLink"&gt;2 (34)&lt;/a&gt;
    &lt;/li&gt;

&lt;/ul&gt;
</code></pre>

<p>Here is my code:</p>

<pre><code>&lt;?PHP 
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_COOKIE, "ChosenSite=www; SportsDirect_AnonymousUserCurrency=GBP; language=en-GB");
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($curl, CURLOPT_SSLVERSION, 3);
    curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 10);
    curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
    curl_setopt($curl, CURLOPT_VERBOSE, true);
    $str = curl_exec($curl);  
    curl_close($curl);  

    $html= str_get_html($str);

    libxml_use_internal_errors(true); 
    $doc = new DOMDocument();
    $doc-&gt;loadHTML($str);

    $xpath = new DOMXpath($doc);


    $i = 0;
    $Sizes = $xpath-&gt;query('//ul[@id="dnn_ctr103511_ViewTemplate_ctl00_ctl14_ulSizes"]//li/a');
    foreach ($Sizes-&gt;item() as $item) {
        $title = $item-&gt;nodeValue;
        $N = $i++;  
?&gt;
        &lt;div class="SizeButtons &lt;?PHP if($N ==  0){ echo "SizeSelected";} ?&gt;" data-title="&lt;?PHP echo $title;?&gt;" data-number="&lt;?PHP echo $N;?&gt;"&gt;&lt;?PHP echo $title; ?&gt;&lt;/div&gt;    
    }         
?&gt;
</code></pre>

<p>Unfortunatelly it seems that i have mistake in my code somewhere because i can get the results. As you can see there are several DOM elements under <code>//ul[@id="dnn_ctr103511_ViewTemplate_ctl00_ctl14_ulSizes"]//li/a</code> but i can not get them.</p>

<p>Where is my mistake and how can i fix it?</p>

<p>Thanks in advance!</p>