1
I have a return of an XML that is a loop (because it’s the only way I know how to call back) but in XML I have two det
, det nItem="1"
and det nItem="2"
which are 2 products, inside them is the tag cEAN
which is the one I need separated into different variables to be able to use each individually cEAN
.
My call
import xml.etree.ElementTree as ET
tree = ET.parse("C:\\Users\\Expedição\\Videos\\XML\\xml_teste2.xml")
root = tree.getroot()
ns = {'nfe': 'http://www.portalfiscal.inf.br/nfe'}
for det in root.findall('.//nfe:det', ns):
quantidade = det.find('.//nfe:qCom', ns).text
EAN = det.find('.//nfe:cEAN', ns).text
print (EAN.split())
The XML used:
<nfeProc xmlns="http://www.portalfiscal.inf.br/nfe" versao="4.00">
<NFe xmlns="http://www.portalfiscal.inf.br/nfe">
<infNFe Id="NFe35200811625533000185550010000043291000219014" versao="4.00">
<ide>
...
</ide>
<emit>
...
</emit>
<dest>
<CNPJ>33737452000100</CNPJ>
<xNome>GP CAVALCANTE COMERCIO, IMPORTACAO E EXPORTACAO DE PECAS AUT</xNome>
<enderDest>
...
</enderDest>
<indIEDest>1</indIEDest>
<IE>799164503118</IE>
<email>[email protected]; [email protected]</email>
</dest>
<det nItem="1">
<prod>
<cProd>ET-CAM 01</cProd>
<cEAN/>
<xProd>CAMERA ESTAC MISTA (FURADA + SUP. BORBOLETA)</xProd>
<NCM>85258029</NCM>
<CEST>2106300</CEST>
<CFOP>5405</CFOP>
<uCom>UNI</uCom>
<qCom>20.0000</qCom>
<vUnCom>22.0000</vUnCom>
<vProd>440.00</vProd>
<cEANTrib/>
<uTrib>UNI</uTrib>
<qTrib>20.0000</qTrib>
<vUnTrib>22.0000</vUnTrib>
<indTot>1</indTot>
</prod>
<imposto>
...
</imposto>
</det>
<det nItem="2">
<prod>
<cProd>ET-CAM 02</cProd>
<cEAN>7898622140258</cEAN>
<xProd>CAMERA ESTAC DIANTEIRA</xProd>
<NCM>85258029</NCM>
<CEST>2106300</CEST>
<CFOP>5405</CFOP>
<uCom>UNI</uCom>
<qCom>10.0000</qCom>
<vUnCom>26.9000</vUnCom>
<vProd>269.00</vProd>
<cEANTrib>7898622140258</cEANTrib>
<uTrib>UNI</uTrib>
<qTrib>10.0000</qTrib>
<vUnTrib>26.9000</vUnTrib>
<indTot>1</indTot>
</prod>
thank you so much for your help.
– user198451