-2
I’m with an XML file reading system in progress, I chose the language that I do not have as much PHP ease, the fact and that I do not know how to take several files and allocate in a variable, I’m only taking the temporary address of the files and do the reading, all the process that has to be done and shown on the screen is already working but unified, I can only do reading only 1 file by you and need to read several files at a time.
Does anyone know how to read many XML ?
Entry code:
<form action="teste2.php" method="POST" enctype="multipart/form-data">
<input type="file" name="entXML" multiple="multiple"><br>
<input type="submit" value="LER_ARQUIVO">
</form>
Treatment with PHP
<?php
//Instanciando o OBJ
$xml = new DOMdocument();
//Pegando o TMP do FORM
$arquivo = $_FILES['entXML']['tmp_name'];
//Carregando o XML
$xml ->load($arquivo) or die("Erro ao carregar arquivo XML");
//Entra dentro do NÓ pai do XML
$arquivoXML = $xml->getElementsByTagName( "nfeProc" );
//Navegando no Nodes(Nós)
foreach( $arquivoXML as $xml){
//Pega Nome
$nomes = $xml->getElementsByTagName( "xNome" );
$nome = $nomes->item(0)->nodeValue;
//Pega CNPJ
$cnpjS = $xml->getElementsByTagName( "CNPJ" );
$cnpj = $cnpjS->item(0)->nodeValue;
//Mostra dados da Tabela EMIT
echo "<b>Nome:</b> $nome"."   ";
echo "<b>CNPJ:</b> $cnpj";
echo"<br>";
echo"<br>";
echo"<br>";
echo"-------------------------------VALORES----------------------------------";
echo"<br>";
//-----------------------------------------------------------------
//Entra dentro do NODE "ide"
foreach( $arquivoXML as $xml){
//Pega Numero da NF
$nfs = $xml->getElementsByTagName( "nNF" );
$nf = $nfs->item(0)->nodeValue;
//Pega Data de Emissão da NF
$dataEMS = $xml->getElementsByTagName( "dhEmi" );
$dataEmi = $dataEMS->item(0)->nodeValue;
//Pega CFOP
$cfopS = $xml->getElementsByTagName( "CFOP" );
$cfop = $cfopS->item(0)->nodeValue;
//Pega Valor do XML
$vaPagS= $xml->getElementsByTagName( "vPag" );
$vaPag = $vaPagS->item(0)->nodeValue;
//Pega Status da Sefaz XML
$motivoS= $xml->getElementsByTagName( "xMotivo" );
$motivo = $motivoS->item(0)->nodeValue;
//Mostra Tabela na Tela
echo "<table border=1;>";
echo "<tr>";
echo "<th>Nº NF</th>" ;
echo "<th>Data Emissão</th>" ;
echo "<th>CFOP</th>" ;
echo "<th>Valor</th>" ;
echo "<th>Status</th>" ;
echo "</tr>";
echo"<tr>";
echo"<td>$nf</td>";
echo"<td>$dataEmi</td>";
echo"<td>$cfop</td>";
echo"<td>$vaPag </td>";
echo"<td>$motivo </td>";
echo"</tr>";
echo "</table>";
}
}
I think what Voce really needs is to open multiple files as an https://www.sobolsoft.com/howtouse/combine-xml-files.htm. I hope I helped you!
– Thiago Vinic
No and that, I need to work on my code for it to read multiple XML, anyway Thanks for the help !
– Gabriel Francisco Santana Sant