I am trying to read an XML file in PHP using the library SimpleXMLElement but when obtaining its value I find the following error:
Fatal error: Uncaught Error: Call to a member function attributes() on null
The XML file I am trying to read is the following:
<?xml version="1.0" encoding="UTF-8"?>
<cfdi:Comprobante Version="3.3" Total="45264.13">
    <cfdi:Emisor Rfc="ABC123456AB1" Nombre="JOHN DOE"/>
     <cfdi:Conceptos>
         <cfdi:Concepto ValorUnitario="93.80">
        </cfdi:Concepto>
    </cfdi:Conceptos>
     <cfdi:Complemento>
        <tfd:Digital Version="1.1" Sello="BXTJPwDh+" NoCertificado="0000100"
            FechaTimbrado="2019-07-18" UID="C58C"
            xmlns:tfd="http://www.stackoverflow.com"/>
    </cfdi:Complemento>
</cfdi:Comprobante>
I am reading different values inside the XML such as the rfc and total and without them I have no problems.
The value that I am trying to read and am getting trouble with is UID.
The way I am reading the XML values is as follows:
 $xml = new SimpleXMlElement( $_FILES['XmlToUpload']['tmp_name'], 0, true );
  $factura = (isset($_POST['factura'])) ? trim($_POST['factura']) : '';
  $total = (float)$xml['Total'];      
  $rfc = (string)$xml->children('cfdi',true)->Emisor[0]->attributes()['Rfc'];
  $uid = (string)$xml->children('tfd',true)->Digital[0]->attributes()['UID'];
I repeat with rfc and total I have not had any problem, I am following the same idea but to read the UID if it generates the error mentioned at the beginning.
You know if the way I should read this value of is different UID or I am making a mistake.
 
    