title: Extract data from XML with unknown fields with PHP
body: <p>I have a feed with several products in it, but the fields are not known. I want to display a "tree structure" from the file with PHP.</p>
  
  <p>THe XML looks like following:</p>
  
  <pre><code>&lt;products&gt;
    &lt;product id="1"&gt;
      &lt;title&gt;Title of product 1&lt;/title&gt;
      &lt;weight measure="kg"&gt;4000&lt;/weight&gt;
      &lt;specs&gt;
         &lt;spec name="spec1"&gt;
         &lt;value&gt;value spec 1&lt;/value&gt;
         &lt;spec name="spec2"&gt;
         &lt;value&gt;value spec 2&lt;/value&gt;
      &lt;/specs&gt;
    &lt;/product&gt;
    &lt;product id="2"&gt;
      &lt;title&gt;Title of product 2&lt;/title&gt;
      &lt;weight measure="kg"&gt;10000&lt;/weight&gt;
      &lt;specs&gt;
         &lt;spec name="spec1"&gt;
         &lt;value&gt;value spec 1&lt;/value&gt;
         &lt;spec name="spec2"&gt;
         &lt;value&gt;value spec 2&lt;/value&gt;
         &lt;spec name="spec3"&gt;
         &lt;value&gt;value spec 3&lt;/value&gt;
      &lt;/specs&gt;
    &lt;/product&gt;
  &lt;/products&gt;
  </code></pre>
  
  <p>I'd like my PHP to display something like this so that I can insert these values in the database:</p>
  
  <pre><code>Product: 1
  title: Title of product 1
  weight: 4000
  spec1: value spec 1
  spec2: value spec 2
  
  Product: 2
  title: Title of product 2
  weight: 10000
  spec1: value spec 1
  spec2: value spec 2
  spec3: value spec 3
  </code></pre>
  
  <p>As mentioned, the feeds are differently every time, with different fields. Thats making it more difficult to me..</p>
  
  <pre><code>$xml = simplexml_load_file($feedURL);
  foreach($xml-&gt;product as $products) {
      echo '&gt;.'.$products[ID].'&lt;br&gt;';
      foreach($products-&gt;children() as $properties){
          echo $properties[name].': '.$properties-&gt;value.'&lt;br&gt;';
          foreach($properties-&gt;children() as $aspects){
              echo '---&gt;'.$aspects[name].': '.$aspects-&gt;value.'&lt;br&gt;';
          }
      }
  }
  </code></pre>
  
  <p>It does not work at this moment. How could I fix this?</p>