This way down is simpler.
I’ve been wearing this since 2010.
// Directory for file storing filesystem path
$d = dirname(__FILE__);
$upload_dir = "$d/nfs";
$c = $n = $u = $y = $s = $v = '';
$file = $upload_dir.'/tmp/'.md5(rand()).".test"; // file name
move_uploaded_file($_FILES['file']['tmp_name'], "$file");
// Carrega o XML e o XSL
$xml = simplexml_load_file("$file");
$c = $xml->getName();
switch ($c) {
case "GerarNfseResposta": //PB
$n = $xml->children('nfse', TRUE); //Namesspace as Prefix
$n = $n->ListaNfse->CompNfse->Nfse->InfNfse;
$u = $n->PrestadorServico->IdentificacaoPrestador->CpfCnpj;
$u = ($u->Cpf?$u->Cpf:$u->Cnpj);
$s = $n->Numero+0;
$c = $n->DataEmissao;
$y = substr($c, 0, 4)+0;
$c = date("Y-m-d H:i:s", strtotime($c));
$v = $n->CodigoVerificacao;
echo "<!-- u:$u y:$y s:$s v:$v c:$c -->";
break;
case "CompNfse": //BH
$n = $xml->children('http://www.abrasf.org.br/nfse.xsd'); //Namesspace only
$n = $n->Nfse->InfNfse;
$u = $n->PrestadorServico->IdentificacaoPrestador;
$u = ($u->Cpf?$u->Cpf:$u->Cnpj);
$s = substr($n->Numero, 4)+0;
$c = $n->DataEmissao;
$y = substr($c, 0, 4)+0;
$c = date("Y-m-d H:i:s", strtotime($c));
$v = $n->CodigoVerificacao;
echo "<!-- u:$u y:$y s:$s v:$v c:$c -->";
break;
case 2:
break;
}
unset($xml);
Welcome to Stackoverflow! Asking a tutorial leaves the question outside the scope of SOPT. Try to be more objective in the question, for example: "How do I read an XML file in PHP?"
– Jorge B.