• 0
Sign in to follow this  
grego

(Resolvido) Ler arquivo XML

Question

Saudações à todos

Em toda busca que fiz, só encontrei o exemplo fácil (primário) que é a leitura de um só nó.

O que preciso é ler o XML que retorna validado do SEFAZ. Aquivo com vários nós, ou seja:

enviNFe --> essa tag refere-se ao arquivo XML

NFe -->

infNFe --> essas duas tags referem-se a cada Nota Fiscal (sem dados)

ide --> dados

emit --> dados

prod --> dados

imposto --> dados

transf --> dados

.

.

/ide

/emit

/prod

/imposto

/transf

/infNFe

/NFe

/enviNFe

Se alguém puder me ajudar, fico muito agradecido.

Share this post


Link to post
Share on other sites

6 answers to this question

Recommended Posts

  • 0
Salve,

Poderia, por favor, postar um modelo do XML válido e como esta desenvolvendo o código ?

Eis o arquivo XML (o código PHP está lá no final)

<?xml version="1.0" encoding="UTF-8" ?>
<enviNFe xmlns="http://www.portalfiscal.inf.br/nfe" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" versao="1.07">
<idLote>000000000000001</idLote>
<NFe xmlns="http://www.portalfiscal.inf.br/nfe">
<infNFe versao="1.0" Id="NFe4109100160900300019055001000000152382294794">
<ide>
<cUF>41</cUF>
<cNF>382294794</cNF>
<natOp>venda</natOp>
<indPag>0</indPag>
<mod>55</mod>
<serie>001</serie>
<nNF>000000152</nNF>
<dEmi>0910</dEmi>
<dSaiEnt>0910</dSaiEnt>
<tpNF>1</tpNF>
<cMunFG>4106902</cMunFG>
<tpImp>1</tpImp>
<tpEmis>1</tpEmis>
<cDV>9</cDV>
<tpAmb>2</tpAmb>
<finNFe>1</finNFe>
<procEmi>0</procEmi>
<verProc>1.0.0</verProc>
</ide>
<emit>
<xCNPJ>01.609.003/0001-90</xCNPJ>
<xNome>Primeira Empresa</xNome>
<enderEmit>
<xLgr>xxxxx Primeira Empresa</xLgr>
<nro>12345</nro>
<xBairro>Bairro Primeira Empr</xBairro>
<cMun>4106902</cMun>
<xMun>Cidade Primeira Empr</xMun>
<UF>PR</UF>
</enderEmit>
<IE>ISENTO</IE>
</emit>
<dest>
<xCNPJ>01609003000190</xCNPJ>
<xNome>Antonio Jovinski Rocha</xNome>
<enderDest>
<xLgr>Avenida Brasil</xLgr>
<nro></nro>
<xBairro>Santo Antonio</xBairro>
<cMun>99999</cMun>
<xMun>XXXXX</xMun>
<UF>PR</UF>
</enderDest>
<IE>ISENTO</IE>
</dest>
<det nItem='1'>
<prod>
<cProd>8000</cProd>
<xProd>Oito mil</xProd>
<vProd>146.00</vProd>
</prod>
<imposto>
<ICMS>
<icms00>
<CST>00</CST>
<modBC>1</modBC>
<vBC>146.00</vBC>
<pICMS>14.23</pICMS>
<vICMS>20.7758</vICMS>
</icms00>
</ICMS>
<PIS>
<PISAliq>
<CST>01</CST>
<vBC>146.00</vBC>
<pPIS>0.65</pPIS>
<vPIS>0.949</vPIS>
</PISAliq>
</PIS>
<COFINS>
<COFINSAliq>
<CST>01</CST>
<vBC>146.00</vBC>
<pCOFINS>3</pCOFINS>
<vCOFINS>4.38</vCOFINS>
</COFINSAliq>
</COFINS>
</imposto>
</det>
<det nItem='2'>
<prod>
<cProd>4002</cProd>
<xProd>Quatro mil e dois</xProd>
<vProd>170.00</vProd>
</prod>
<imposto>
<ICMS>
<icms00>
<CST>00</CST>
<modBC>1</modBC>
<vBC>170.00</vBC>
<pICMS>16.35</pICMS>
<vICMS>27.795</vICMS>
</icms00>
</ICMS>
<PIS>
<PISAliq>
<CST>01</CST>
<vBC>170.00</vBC>
<pPIS>0.65</pPIS>
<vPIS>1.105</vPIS>
</PISAliq>
</PIS>
<COFINS>
<COFINSAliq>
<CST>01</CST>
<vBC>170.00</vBC>
<pCOFINS>3</pCOFINS>
<vCOFINS>5.1</vCOFINS>
</COFINSAliq>
</COFINS>
</imposto>
</det>
<det nItem='3'>
<prod>
<cProd>4001</cProd>
<xProd>Quatro mil e um</xProd>
<vProd>150.00</vProd>
</prod>
<imposto>
<ICMS>
<icms00>
<CST>00</CST>
<modBC>1</modBC>
<vBC>150.00</vBC>
<pICMS>17.42</pICMS>
<vICMS>26.13</vICMS>
</icms00>
</ICMS>
<PIS>
<PISAliq>
<CST>01</CST>
<vBC>150.00</vBC>
<pPIS>0.65</pPIS>
<vPIS>0.975</vPIS>
</PISAliq>
</PIS>
<COFINS>
<COFINSAliq>
<CST>01</CST>
<vBC>150.00</vBC>
<pCOFINS>3</pCOFINS>
<vCOFINS>4.5</vCOFINS>
</COFINSAliq>
</COFINS>
</imposto>
</det>
<total>
<ICMSTot>
<vBC>466</vBC>
<vICMS>74.7008</vICMS>
<vPIS>3.029</vPIS>
<vCOFINS>13.98</vCOFINS>
<vNF>466</vNF>
</ICMSTot>
</total>
<transp>
<modFrete>0</modFrete>
<transporta>
<CPF>01609003000190</CPF>
<xNome>Primeiro Transportador</xNome>
</transporta>
</transp>
</infNFe>
</NFe>
<NFe xmlns="http://www.portalfiscal.inf.br/nfe">
<infNFe versao="1.0" Id="NFe4109100160900300019055001000000153359660423">
<ide>
<cUF>41</cUF>
<cNF>359660423</cNF>
<natOp>venda</natOp>
<indPag>0</indPag>
<mod>55</mod>
<serie>001</serie>
<nNF>000000153</nNF>
<dEmi>0910</dEmi>
<dSaiEnt>0910</dSaiEnt>
<tpNF>1</tpNF>
<cMunFG>4106902</cMunFG>
<tpImp>1</tpImp>
<tpEmis>1</tpEmis>
<cDV>0</cDV>
<tpAmb>2</tpAmb>
<finNFe>1</finNFe>
<procEmi>0</procEmi>
<verProc>1.0.0</verProc>
</ide>
<emit>
<xCNPJ>01.609.003/0001-90</xCNPJ>
<xNome>Primeira Empresa</xNome>
<enderEmit>
<xLgr>Endereo da Primeira Empresa</xLgr>
<nro>12345</nro>
<xBairro>Bairro Primeira Empr</xBairro>
<cMun>4106902</cMun>
<xMun>Cidade Primeira Empr</xMun>
<UF>PR</UF>
</enderEmit>
<IE>ISENTO</IE>
</emit>
<dest>
<xCNPJ>01609003000190</xCNPJ>
<xNome>Antonio Prestessss</xNome>
<enderDest>
<xLgr>Rua Projetada</xLgr>
<nro></nro>
<xBairro>Nodari Ii</xBairro>
<cMun>99999</cMun>
<xMun>XXXXX</xMun>
<UF>PR</UF>
</enderDest>
<IE>ISENTO</IE>
</dest>
<det nItem='1'>
<prod>
<cProd>9000</cProd>
<xProd>Nove mil</xProd>
<vProd>682.00</vProd>
</prod>
<imposto>
<ICMS>
<icms00>
<CST>00</CST>
<modBC>1</modBC>
<vBC>682.00</vBC>
<pICMS>13.42</pICMS>
<vICMS>91.5244</vICMS>
</icms00>
</ICMS>
<PIS>
<PISAliq>
<CST>01</CST>
<vBC>682.00</vBC>
<pPIS>0.65</pPIS>
<vPIS>4.433</vPIS>
</PISAliq>
</PIS>
<COFINS>
<COFINSAliq>
<CST>01</CST>
<vBC>682.00</vBC>
<pCOFINS>3</pCOFINS>
<vCOFINS>20.46</vCOFINS>
</COFINSAliq>
</COFINS>
</imposto>
</det>
<total>
<ICMSTot>
<vBC>682</vBC>
<vICMS>91.5244</vICMS>
<vPIS>4.433</vPIS>
<vCOFINS>20.46</vCOFINS>
<vNF>682</vNF>
</ICMSTot>
</total>
<transp>
<modFrete>0</modFrete>
<transporta>
<CPF>01609003000190</CPF>
<xNome>Primeiro Transportador</xNome>
</transporta>
</transp>
</infNFe>
</NFe>
<NFe xmlns="http://www.portalfiscal.inf.br/nfe">
<infNFe versao="1.0" Id="NFe4109100160900300019055001000000154244819816">
<ide>
<cUF>41</cUF>
<cNF>244819816</cNF>
<natOp>venda</natOp>
<indPag>0</indPag>
<mod>55</mod>
<serie>001</serie>
<nNF>000000154</nNF>
<dEmi>0910</dEmi>
<dSaiEnt>0910</dSaiEnt>
<tpNF>1</tpNF>
<cMunFG>4106902</cMunFG>
<tpImp>1</tpImp>
<tpEmis>1</tpEmis>
<cDV>0</cDV>
<tpAmb>2</tpAmb>
<finNFe>1</finNFe>
<procEmi>0</procEmi>
<verProc>1.0.0</verProc>
</ide>
<emit>
<xCNPJ>01.609.003/0001-90</xCNPJ>
<xNome>Primeira Empresa</xNome>
<enderEmit>
<xLgr>Endereo da Primeira Empresa</xLgr>
<nro>12345</nro>
<xBairro>Bairro Primeira Empr</xBairro>
<cMun>4106902</cMun>
<xMun>Cidade Primeira Empr</xMun>
<UF>PR</UF>
</enderEmit>
<IE>ISENTO</IE>
</emit>
<dest>
<xCNPJ>01609003000190</xCNPJ>
<xNome>Antonio Jovinski Rocha</xNome>
<enderDest>
<xLgr>Avenida Brasil</xLgr>
<nro></nro>
<xBairro>Santo Antonio</xBairro>
<cMun>99999</cMun>
<xMun>XXXXX</xMun>
<UF>PR</UF>
</enderDest>
<IE>ISENTO</IE>
</dest>
<det nItem='1'>
<prod>
<cProd>3232</cProd>
<xProd>Tres dois tres dois</xProd>
<vProd>94.00</vProd>
</prod>
<imposto>
<ICMS>
<icms00>
<CST>00</CST>
<modBC>1</modBC>
<vBC>94.00</vBC>
<pICMS>12.55</pICMS>
<vICMS>11.797</vICMS>
</icms00>
</ICMS>
<PIS>
<PISAliq>
<CST>01</CST>
<vBC>94.00</vBC>
<pPIS>0.65</pPIS>
<vPIS>0.611</vPIS>
</PISAliq>
</PIS>
<COFINS>
<COFINSAliq>
<CST>01</CST>
<vBC>94.00</vBC>
<pCOFINS>3</pCOFINS>
<vCOFINS>2.82</vCOFINS>
</COFINSAliq>
</COFINS>
</imposto>
</det>
<det nItem='2'>
<prod>
<cProd>8787</cProd>
<xProd>Oito sete oito sete Roupeiro</xProd>
<vProd>280.00</vProd>
</prod>
<imposto>
<ICMS>
<icms00>
<CST>00</CST>
<modBC>1</modBC>
<vBC>280.00</vBC>
<pICMS>12.00</pICMS>
<vICMS>33.6</vICMS>
</icms00>
</ICMS>
<PIS>
<PISAliq>
<CST>01</CST>
<vBC>280.00</vBC>
<pPIS>0.65</pPIS>
<vPIS>1.82</vPIS>
</PISAliq>
</PIS>
<COFINS>
<COFINSAliq>
<CST>01</CST>
<vBC>280.00</vBC>
<pCOFINS>3</pCOFINS>
<vCOFINS>8.4</vCOFINS>
</COFINSAliq>
</COFINS>
</imposto>
</det>
<total>
<ICMSTot>
<vBC>374</vBC>
<vICMS>45.397</vICMS>
<vPIS>2.431</vPIS>
<vCOFINS>11.22</vCOFINS>
<vNF>374</vNF>
</ICMSTot>
</total>
<transp>
<modFrete>0</modFrete>
<transporta>
<CPF>01609003000190</CPF>
<xNome>Primeiro Transportador</xNome>
</transporta>
</transp>
</infNFe>
</NFe>
</enviNFe>
Com esse código a seguir, mostra a primeira NF 3 vezes (são 3 NFs diferentes, porém mostra a 1º 3 vezes)
<?php
require('conexao.php');
$xml = simplexml_load_file('primeiro.xml');
foreach($xml->NFe as $NFe)
{
    foreach($xml->NFe->infNFe as $infNFe)
    {
        foreach($xml->NFe->infNFe->ide as $ide)
        {
            $numeroNF = $ide->nNF;
            $serie = $ide->serie;
            foreach($xml->NFe->infNFe->emit as $emit)
            {
                $xNome = $emit->xNome;
                foreach($xml->NFe->infNFe->emit->enderEmit as $enderEmit)
                {
                    $xLgr = $enderEmit->xLgr;
                    $xBairro = $enderEmit->xBairro;
                    $xMun = $enderEmit->xMun;
                    $UF = $enderEmit->UF;
                    echo $numeroNF;
                    echo $serie;
                    echo $xNome;
                    echo $xLgr;
                    echo $xBairro;
                    echo $xMun;
                    echo $UF;
                    echo "<br>";
                }
            }
        }
    }
}
?>

Share this post


Link to post
Share on other sites
  • 0

Salve,

Bom, me desculpe pela demora, é que só acabei meu dia agora e lembrei de vir lhe responder

Espero que o código abaixo sirva de base para você ir montando seu conteudo

file.xml

<?xml version="1.0" encoding="UTF-8" ?>
<enviNFe xmlns="http://www.portalfiscal.inf.br/nfe" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" versao="1.07">
<idLote>000000000000001</idLote>
<NFe xmlns="http://www.portalfiscal.inf.br/nfe">
<infNFe versao="1.0" Id="NFe4109100160900300019055001000000152382294794">
<ide>
<cUF>41</cUF>
<cNF>382294794</cNF>
<natOp>venda</natOp>
<indPag>0</indPag>
<mod>55</mod>
<serie>001</serie>
<nNF>000000152</nNF>
<dEmi>0910</dEmi>
<dSaiEnt>0910</dSaiEnt>
<tpNF>1</tpNF>
<cMunFG>4106902</cMunFG>
<tpImp>1</tpImp>
<tpEmis>1</tpEmis>
<cDV>9</cDV>
<tpAmb>2</tpAmb>
<finNFe>1</finNFe>
<procEmi>0</procEmi>
<verProc>1.0.0</verProc>
</ide>
<emit>
<xCNPJ>01.609.003/0001-90</xCNPJ>
<xNome>Primeira Empresa</xNome>
<enderEmit>
<xLgr>xxxxx Primeira Empresa</xLgr>
<nro>12345</nro>
<xBairro>Bairro Primeira Empr</xBairro>
<cMun>4106902</cMun>
<xMun>Cidade Primeira Empr</xMun>
<UF>PR</UF>
</enderEmit>
<IE>ISENTO</IE>
</emit>
<dest>
<xCNPJ>01609003000190</xCNPJ>
<xNome>Antonio Jovinski Rocha</xNome>
<enderDest>
<xLgr>Avenida Brasil</xLgr>
<nro></nro>
<xBairro>Santo Antonio</xBairro>
<cMun>99999</cMun>
<xMun>XXXXX</xMun>
<UF>PR</UF>
</enderDest>
<IE>ISENTO</IE>
</dest>
<det nItem='1'>
<prod>
<cProd>8000</cProd>
<xProd>Oito mil</xProd>
<vProd>146.00</vProd>
</prod>
<imposto>
<ICMS>
<icms00>
<CST>00</CST>
<modBC>1</modBC>
<vBC>146.00</vBC>
<pICMS>14.23</pICMS>
<vICMS>20.7758</vICMS>
</icms00>
</ICMS>
<PIS>
<PISAliq>
<CST>01</CST>
<vBC>146.00</vBC>
<pPIS>0.65</pPIS>
<vPIS>0.949</vPIS>
</PISAliq>
</PIS>
<COFINS>
<COFINSAliq>
<CST>01</CST>
<vBC>146.00</vBC>
<pCOFINS>3</pCOFINS>
<vCOFINS>4.38</vCOFINS>
</COFINSAliq>
</COFINS>
</imposto>
</det>
<det nItem='2'>
<prod>
<cProd>4002</cProd>
<xProd>Quatro mil e dois</xProd>
<vProd>170.00</vProd>
</prod>
<imposto>
<ICMS>
<icms00>
<CST>00</CST>
<modBC>1</modBC>
<vBC>170.00</vBC>
<pICMS>16.35</pICMS>
<vICMS>27.795</vICMS>
</icms00>
</ICMS>
<PIS>
<PISAliq>
<CST>01</CST>
<vBC>170.00</vBC>
<pPIS>0.65</pPIS>
<vPIS>1.105</vPIS>
</PISAliq>
</PIS>
<COFINS>
<COFINSAliq>
<CST>01</CST>
<vBC>170.00</vBC>
<pCOFINS>3</pCOFINS>
<vCOFINS>5.1</vCOFINS>
</COFINSAliq>
</COFINS>
</imposto>
</det>
<det nItem='3'>
<prod>
<cProd>4001</cProd>
<xProd>Quatro mil e um</xProd>
<vProd>150.00</vProd>
</prod>
<imposto>
<ICMS>
<icms00>
<CST>00</CST>
<modBC>1</modBC>
<vBC>150.00</vBC>
<pICMS>17.42</pICMS>
<vICMS>26.13</vICMS>
</icms00>
</ICMS>
<PIS>
<PISAliq>
<CST>01</CST>
<vBC>150.00</vBC>
<pPIS>0.65</pPIS>
<vPIS>0.975</vPIS>
</PISAliq>
</PIS>
<COFINS>
<COFINSAliq>
<CST>01</CST>
<vBC>150.00</vBC>
<pCOFINS>3</pCOFINS>
<vCOFINS>4.5</vCOFINS>
</COFINSAliq>
</COFINS>
</imposto>
</det>
<total>
<ICMSTot>
<vBC>466</vBC>
<vICMS>74.7008</vICMS>
<vPIS>3.029</vPIS>
<vCOFINS>13.98</vCOFINS>
<vNF>466</vNF>
</ICMSTot>
</total>
<transp>
<modFrete>0</modFrete>
<transporta>
<CPF>01609003000190</CPF>
<xNome>Primeiro Transportador</xNome>
</transporta>
</transp>
</infNFe>
</NFe>
<NFe xmlns="http://www.portalfiscal.inf.br/nfe">
<infNFe versao="1.0" Id="NFe4109100160900300019055001000000153359660423">
<ide>
<cUF>41</cUF>
<cNF>359660423</cNF>
<natOp>venda</natOp>
<indPag>0</indPag>
<mod>55</mod>
<serie>001</serie>
<nNF>000000153</nNF>
<dEmi>0910</dEmi>
<dSaiEnt>0910</dSaiEnt>
<tpNF>1</tpNF>
<cMunFG>4106902</cMunFG>
<tpImp>1</tpImp>
<tpEmis>1</tpEmis>
<cDV>0</cDV>
<tpAmb>2</tpAmb>
<finNFe>1</finNFe>
<procEmi>0</procEmi>
<verProc>1.0.0</verProc>
</ide>
<emit>
<xCNPJ>01.609.003/0001-90</xCNPJ>
<xNome>Primeira Empresa</xNome>
<enderEmit>
<xLgr>Endereo da Primeira Empresa</xLgr>
<nro>12345</nro>
<xBairro>Bairro Primeira Empr</xBairro>
<cMun>4106902</cMun>
<xMun>Cidade Primeira Empr</xMun>
<UF>PR</UF>
</enderEmit>
<IE>ISENTO</IE>
</emit>
<dest>
<xCNPJ>01609003000190</xCNPJ>
<xNome>Antonio Prestessss</xNome>
<enderDest>
<xLgr>Rua Projetada</xLgr>
<nro></nro>
<xBairro>Nodari Ii</xBairro>
<cMun>99999</cMun>
<xMun>XXXXX</xMun>
<UF>PR</UF>
</enderDest>
<IE>ISENTO</IE>
</dest>
<det nItem='1'>
<prod>
<cProd>9000</cProd>
<xProd>Nove mil</xProd>
<vProd>682.00</vProd>
</prod>
<imposto>
<ICMS>
<icms00>
<CST>00</CST>
<modBC>1</modBC>
<vBC>682.00</vBC>
<pICMS>13.42</pICMS>
<vICMS>91.5244</vICMS>
</icms00>
</ICMS>
<PIS>
<PISAliq>
<CST>01</CST>
<vBC>682.00</vBC>
<pPIS>0.65</pPIS>
<vPIS>4.433</vPIS>
</PISAliq>
</PIS>
<COFINS>
<COFINSAliq>
<CST>01</CST>
<vBC>682.00</vBC>
<pCOFINS>3</pCOFINS>
<vCOFINS>20.46</vCOFINS>
</COFINSAliq>
</COFINS>
</imposto>
</det>
<total>
<ICMSTot>
<vBC>682</vBC>
<vICMS>91.5244</vICMS>
<vPIS>4.433</vPIS>
<vCOFINS>20.46</vCOFINS>
<vNF>682</vNF>
</ICMSTot>
</total>
<transp>
<modFrete>0</modFrete>
<transporta>
<CPF>01609003000190</CPF>
<xNome>Primeiro Transportador</xNome>
</transporta>
</transp>
</infNFe>
</NFe>
<NFe xmlns="http://www.portalfiscal.inf.br/nfe">
<infNFe versao="1.0" Id="NFe4109100160900300019055001000000154244819816">
<ide>
<cUF>41</cUF>
<cNF>244819816</cNF>
<natOp>venda</natOp>
<indPag>0</indPag>
<mod>55</mod>
<serie>001</serie>
<nNF>000000154</nNF>
<dEmi>0910</dEmi>
<dSaiEnt>0910</dSaiEnt>
<tpNF>1</tpNF>
<cMunFG>4106902</cMunFG>
<tpImp>1</tpImp>
<tpEmis>1</tpEmis>
<cDV>0</cDV>
<tpAmb>2</tpAmb>
<finNFe>1</finNFe>
<procEmi>0</procEmi>
<verProc>1.0.0</verProc>
</ide>
<emit>
<xCNPJ>01.609.003/0001-90</xCNPJ>
<xNome>Primeira Empresa</xNome>
<enderEmit>
<xLgr>Endereo da Primeira Empresa</xLgr>
<nro>12345</nro>
<xBairro>Bairro Primeira Empr</xBairro>
<cMun>4106902</cMun>
<xMun>Cidade Primeira Empr</xMun>
<UF>PR</UF>
</enderEmit>
<IE>ISENTO</IE>
</emit>
<dest>
<xCNPJ>01609003000190</xCNPJ>
<xNome>Antonio Jovinski Rocha</xNome>
<enderDest>
<xLgr>Avenida Brasil</xLgr>
<nro></nro>
<xBairro>Santo Antonio</xBairro>
<cMun>99999</cMun>
<xMun>XXXXX</xMun>
<UF>PR</UF>
</enderDest>
<IE>ISENTO</IE>
</dest>
<det nItem='1'>
<prod>
<cProd>3232</cProd>
<xProd>Tres dois tres dois</xProd>
<vProd>94.00</vProd>
</prod>
<imposto>
<ICMS>
<icms00>
<CST>00</CST>
<modBC>1</modBC>
<vBC>94.00</vBC>
<pICMS>12.55</pICMS>
<vICMS>11.797</vICMS>
</icms00>
</ICMS>
<PIS>
<PISAliq>
<CST>01</CST>
<vBC>94.00</vBC>
<pPIS>0.65</pPIS>
<vPIS>0.611</vPIS>
</PISAliq>
</PIS>
<COFINS>
<COFINSAliq>
<CST>01</CST>
<vBC>94.00</vBC>
<pCOFINS>3</pCOFINS>
<vCOFINS>2.82</vCOFINS>
</COFINSAliq>
</COFINS>
</imposto>
</det>
<det nItem='2'>
<prod>
<cProd>8787</cProd>
<xProd>Oito sete oito sete Roupeiro</xProd>
<vProd>280.00</vProd>
</prod>
<imposto>
<ICMS>
<icms00>
<CST>00</CST>
<modBC>1</modBC>
<vBC>280.00</vBC>
<pICMS>12.00</pICMS>
<vICMS>33.6</vICMS>
</icms00>
</ICMS>
<PIS>
<PISAliq>
<CST>01</CST>
<vBC>280.00</vBC>
<pPIS>0.65</pPIS>
<vPIS>1.82</vPIS>
</PISAliq>
</PIS>
<COFINS>
<COFINSAliq>
<CST>01</CST>
<vBC>280.00</vBC>
<pCOFINS>3</pCOFINS>
<vCOFINS>8.4</vCOFINS>
</COFINSAliq>
</COFINS>
</imposto>
</det>
<total>
<ICMSTot>
<vBC>374</vBC>
<vICMS>45.397</vICMS>
<vPIS>2.431</vPIS>
<vCOFINS>11.22</vCOFINS>
<vNF>374</vNF>
</ICMSTot>
</total>
<transp>
<modFrete>0</modFrete>
<transporta>
<CPF>01609003000190</CPF>
<xNome>Primeiro Transportador</xNome>
</transporta>
</transp>
</infNFe>
</NFe>
</enviNFe>
teste.php
<?php
try
{
    $object = simplexml_load_file('file.xml');
    echo '<table border="1">
            <tr valign="middle">
                <td><strong>Numero</strong></td>
                <td><strong>Serie</strong></td>
            </tr>';
    foreach($object->NFe as $key => $item)
    {
        if(isset($item->infNFe))
        {
            echo '  <tr>
                        <td>'.$item->infNFe->ide->nNF.'</td>
                        <td>'.$item->infNFe->ide->serie.'</td>
                    </tr>
                    ';
        }
    }
    echo '</table>';
}
catch(Exception $e)
{
    echo $e->getMessage();
}

Abraços

Share this post


Link to post
Share on other sites
  • 0

BOA NOITE PESSOAL !!!

Estou desenvolvendo uma leitura e captura de XML em meu API...

Consegui ajustar algumas coisas conforme as orientações acima, porém quando a NFe possui mais de um item, este código não lança os demais itens da Nota... Alguém pode me ajudar ???

Grato...

Share this post


Link to post
Share on other sites
  • 0

Boa tarde,

estava com o mesmo problema do grego, também conseguir resolver, porém gostaria de saber como faço pra ler múltiplos XML´s em um único input .

Agradeço !

<?php

$target_file = basename($_FILES["arquivo"]["name"]);

    $object = simplexml_load_file($target_file);
    echo '<table border="1">
            <tr valign="middle">
                <td><strong>Numero</strong></td>
                <td><strong>Serie</strong></td>
                <td><strong>CNPJ</strong></td>
            </tr>';
    foreach($object->NFe as $key => $item)
    {
        
            echo '  <tr>
                        <td>'.$item->infNFe->ide->nNF.'</td>
                        <td>'.$item->infNFe->ide->serie.'</td>
                        <td>'.$item->infNFe->emit->CNPJ.'</td>
                    </tr>
                    ';
        
    }
    echo '</table>';

?>

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this