title: xml foreach inserting into database multiple child nodes
body: <p>I'm having trouble with an xml foreach where I need to enter multiple child nodes into a database</p>
  
  <p>so for xml section</p>
  
  <pre><code>&lt;Pieces&gt;
      &lt;Piece&gt;
          &lt;PieceNumber&gt;1&lt;/PieceNumber&gt;
          &lt;Depth&gt;5&lt;/Depth&gt;
          &lt;Width&gt;5&lt;/Width&gt;
          &lt;Height&gt;5&lt;/Height&gt;
          &lt;Weight&gt;1&lt;/Weight&gt;
          &lt;PackageType&gt;PA&lt;/PackageType&gt;
          &lt;DimWeight&gt;0.025000&lt;/DimWeight&gt;
          &lt;DataIdentifier&gt;J&lt;/DataIdentifier&gt;
          &lt;LicensePlate&gt;JD014600002433049632&lt;/LicensePlate&gt;
          &lt;LicensePlateBarCode&gt;iVBORw0KGgoAAAANSUhEUgAAAZYAAABeAQMAAAA6+qC4AAAABlBMVEX///8AAABVwtN+AAAAaElEQVR42u3LIRJAQBiA0Z9AUqStextHUSTJCMRVzFDYYLiNO2whklSNM2jC9/rzRKSIymk3eaXXOqzjI5jvZnDipaLax6klUVenV5vZcDy33oj48h2Hw+FwOBwOh8PhcDgcDofzp/MC4ZwWvNbw1agAAAAASUVORK5CYII=&lt;/LicensePlateBarCode&gt;
      &lt;/Piece&gt;
      &lt;Piece&gt;
          &lt;PieceNumber&gt;2&lt;/PieceNumber&gt;
          &lt;Depth&gt;5&lt;/Depth&gt;
          &lt;Width&gt;5&lt;/Width&gt;
          &lt;Height&gt;5&lt;/Height&gt;
          &lt;Weight&gt;1&lt;/Weight&gt;
          &lt;PackageType&gt;PA&lt;/PackageType&gt;
          &lt;DimWeight&gt;0.025000&lt;/DimWeight&gt;
          &lt;DataIdentifier&gt;J&lt;/DataIdentifier&gt;
          &lt;LicensePlate&gt;JD014600002433049633&lt;/LicensePlate&gt;
          &lt;LicensePlateBarCode&gt;iVBORw0KGgoAAAANSUhEUgAAAZYAAABeAQMAAAA6+qC4AAAABlBMVEX///8AAABVwtN+AAAAaElEQVR42u3LIRJAQBiA0X83kBRpi+A2jkKWdoSVzCpmKJLhNu6gEDVV4wya8L3+lIjYqJoOX7p0rcM6PoP5bsdNVC6mezazZObqU9ecVifFPngRLd9xOBwOh8PhcDgcDofD4XA4fzov9XcVvFOzTc8AAAAASUVORK5CYII=&lt;/LicensePlateBarCode&gt;
      &lt;/Piece&gt;
  &lt;/Pieces&gt;
  </code></pre>
  
  <p>and I want to enter both  values</p>
  
  <p>when I use the below, I get the same value twice</p>
  
  <p>// enter pieces into database</p>
  
  <pre><code>foreach ($xml-&gt;Pieces-&gt;children() as $plate)
  {
      $pl = $xml-&gt;Pieces-&gt;Piece-&gt;LicensePlate;
      $query4 = "INSERT INTO pieceplates" 
              . " ( waybill, plate ) " 
              . " VALUES ('$Waybill', '$pl')"; 
              //execute the query 
      $result4 = mysql_query($query4) 
      or die("There has been a problem entering pieces.");
      $pl = $xml-&gt;Pieces-&gt;Piece-&gt;LicensePlate;
  }
  </code></pre>
  
  <p>Any help appreciated</p>