Converting the server-requested XML format data into array and sending back to front-end

I am beginner in using JS/PHP for making license server request based webpage. Right now, I am requesting server’s customer information and make this into array and sends back to the front-end. I request with license ID and if it is valid, then the database sends back the customer information and number of license IDs. Which means that one customer ID can have multiple licenses. The server sends out the XML formatted data and I am trying to make this into array and send back to front-end. The license ID itself is not “sensitive” data so it is okay to be exposed to the front-end.

The XML formatted data is looks like this…

<CustomerData>
<Customer>
<FirstName>TEST FIRST</FirstName>
<LastName>TEST LAST</LastName>
</Customer>
<License>
<LicenseID>11223344</LicenseID>
<ProductID>5448</ProductID>
</License>
<License>
<LicenseID>11223345</LicenseID>
<ProductID>4444</ProductID>
</License>

I tried to make this into array using foreach inside the PHP, but it always gives back empty array of licenses.
I tried to solve with this code…

$xml = simplexml_load_string($result);
if (!empty($xml->CustomerData) && !empty($xml->CustomerData->License)) {
  foreach ($xml->CustomerData->License as $license) {
    $licenseID = (string) $license->LicenseID;
    $productID = (string) $license->ProductID;
    $licenses[] = [
      'licenseID' => $licenseID,
      'productID ' => $productID 
    ];
  }
} else {
error_log('Error');
}
echo json_encode(['licenses' => $licenses]);