xml foreach将多个子节点插入数据库

I'm having trouble with an xml foreach where I need to enter multiple child nodes into a database

so for xml section

<Pieces>
    <Piece>
        <PieceNumber>1</PieceNumber>
        <Depth>5</Depth>
        <Width>5</Width>
        <Height>5</Height>
        <Weight>1</Weight>
        <PackageType>PA</PackageType>
        <DimWeight>0.025000</DimWeight>
        <DataIdentifier>J</DataIdentifier>
        <LicensePlate>JD014600002433049632</LicensePlate>
        <LicensePlateBarCode>iVBORw0KGgoAAAANSUhEUgAAAZYAAABeAQMAAAA6+qC4AAAABlBMVEX///8AAABVwtN+AAAAaElEQVR42u3LIRJAQBiA0Z9AUqStextHUSTJCMRVzFDYYLiNO2whklSNM2jC9/rzRKSIymk3eaXXOqzjI5jvZnDipaLax6klUVenV5vZcDy33oj48h2Hw+FwOBwOh8PhcDgcDofzp/MC4ZwWvNbw1agAAAAASUVORK5CYII=</LicensePlateBarCode>
    </Piece>
    <Piece>
        <PieceNumber>2</PieceNumber>
        <Depth>5</Depth>
        <Width>5</Width>
        <Height>5</Height>
        <Weight>1</Weight>
        <PackageType>PA</PackageType>
        <DimWeight>0.025000</DimWeight>
        <DataIdentifier>J</DataIdentifier>
        <LicensePlate>JD014600002433049633</LicensePlate>
        <LicensePlateBarCode>iVBORw0KGgoAAAANSUhEUgAAAZYAAABeAQMAAAA6+qC4AAAABlBMVEX///8AAABVwtN+AAAAaElEQVR42u3LIRJAQBiA0X83kBRpi+A2jkKWdoSVzCpmKJLhNu6gEDVV4wya8L3+lIjYqJoOX7p0rcM6PoP5bsdNVC6mezazZObqU9ecVifFPngRLd9xOBwOh8PhcDgcDofD4XA4fzov9XcVvFOzTc8AAAAASUVORK5CYII=</LicensePlateBarCode>
    </Piece>
</Pieces>

and I want to enter both values

when I use the below, I get the same value twice

// enter pieces into database

foreach ($xml->Pieces->children() as $plate)
{
    $pl = $xml->Pieces->Piece->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->Pieces->Piece->LicensePlate;
}

Any help appreciated

I assume you are using SimpleXML, try this:

$xml = simplexml_load_string($pieces_xml);
foreach ($xml as $piece)
{
    $pl = $piece->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.");
}

mysql_query() btw. has been deprecated since PHP 5.5 and should be replaced by mysqli_query().