1
I am working on a web system that reads XML files on localhost, reading and checks I am able to unroll quiet, only have a little problem some files comes with error, because when generated XML ends up being mounted empty, I am not able to make my Loop Foreach skip this type of file and go to the next one, like this file with error, Node Father is not found and with that the system for Foreach, I have been researching about CONTINUE but I had no success.
//Instanciando o OBJ
$xml = new DOMdocument();
//Pegando o TMP do FORM
$arquivo = $_FILES['entXML']['tmp_name'];
//Entra dentro do NÓ pai do XML
$arquivo[$i] = $xml->getElementsByTagName( "nfeProc" );
for($i = 0; $i < count($arquivo); $i++) {
$totArquivos +=count($arquivo);
foreach( $arquivo as $arquivo[$i]) {//Inicia o Loop pela Variavel que recebe os arquivos.
$xml->load($arquivo[$i]) or die(" ");//Carregando o XML
$arquivo[$i] = $xml->getElementsByTagName( "nfeProc" );//Entra na TAG Pai do XML
if(empty($arquivo[$i]) ){ continue 1; }//Aqui eu verifico se e vazio, mas ele não ta pulando a iteração, o log de erro acusa o arquivo como Vazio(Empty-File)
}
}
Error file img and error free file when opened in browser
Well, the
continue
has everything to be the solution you seek. Could elaborate a [mcve] demonstrating what you tried to do and what was the output obtained?– Woss
for($i = 0; $i < Count($file);$i++ ){ $totArchives +=Count($file); foreach( $file as $file[$i]){ //Loading XML $xml ->load($file[$i]) or die(" "); $file[$i] = $xml->getelementsbytagname( "nfeProc" ); if(Empty($file[$i]) ){ continue 1; }
– Gabriel Francisco Santana Sant
The parent tag and "nfeProc" I’m associating to a variable and then as ta ai on the last line I check if empty, right after I use (continue 1) to pass an iteration. and follow in the next XML.
– Gabriel Francisco Santana Sant
Gabriel, can you [Edit] the question to add this and remember to properly format the code to facilitate reading.
– Woss
What would that line be,
foreach( $arquivo as $arquivo[$i])
?– Woss
The problem and the total number of characters allowed, so I couldn’t even do the formatting properly...
– Gabriel Francisco Santana Sant
This is where I run all the XML files that are in the variable file, files that come from a form before Foreach I run a FOR on the variable file to go through all the files.
– Gabriel Francisco Santana Sant
I only find my question every time I come here. kkkk
– Gabriel Francisco Santana Sant