title: XMLReader differentiating nested nodes with same name
body: <p>Trying to work with an external xml file, which is stacked like this:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;merchandiser xsi:noNamespaceSchemaLocation="merchandiser.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
    &lt;header&gt;
      &lt;merchantId&gt;44235&lt;/merchantId&gt;
      &lt;merchantName&gt;Feelunique (UK)&lt;/merchantName&gt;
      &lt;createdOn&gt;04/27/2020 00:05:33&lt;/createdOn&gt;
    &lt;/header&gt;
    &lt;product part_number="99082" manufacturer_name="Sanctuary Spa" sku_number="99082" name="Sanctuary Spa Sleep Dream Easy Pillow Mist 100ml" product_id="15927186808"&gt;
      &lt;URL&gt;
        &lt;product&gt;https://click.linksynergy.com/link?id=y/LyuzvjryY&amp;offerid=687217.15927186808&amp;type=15&amp;murl=https%3A%2F%2Fwww.feelunique.com%2Fp%2FSanctuary-Spa-Sleep-Dream-Easy-Pillow-Mist-100ml%26curr%3DGBP&lt;/product&gt;
      &lt;/URL&gt;
    &lt;/product&gt;
  &lt;/merchandiser&gt;
  </code></pre>
  
  <p>As you can see the node <code>&lt;product&gt;</code> is used twice, and I need to grab an attribute from the first one, and the value in the second.</p>
  
  <p>My code seems to jump straight to the second one by default and allows me to define the <code>$xml-&gt;value</code> of the second <code>&lt;product&gt;</code> node, but I can't seem to figure out how to separate the two in my code and get the attribute I need.</p>
  
  <pre><code>            while($xml-&gt;read()) {
  
                  if($xml-&gt;nodeType == XMLReader::ELEMENT) {
  
                      if($xml-&gt;localName == 'header') {
  
                          $header = array();
  
                      }
  
                      if($xml-&gt;localName == 'merchantName') {
  
                          $xml-&gt;read();
                          $header['merchant'] = addslashes($xml-&gt;value);
  
                      }
  
                      if($xml-&gt;localName == 'product') {
  
                          $product = array();
                          $product['merchant'] = $header['merchant'];
                          $product['title'] = $xml-&gt;getAttribute('name');
  
                      }
  
                      if($xml-&gt;localName == 'product') {
  
                          $xml-&gt;read();
                          $product['link'] = $xml-&gt;value;
  
                      }
  }
  }
  </code></pre>
  
  <p>Can somebody point me in the right direction as to how I can achieve both values in my <code>php</code> code?</p>