FONTE NFE VB.NET
Alguém poderia me conseguir algum TXT da versão 2.00,que esteja certo pra dar uma olhada em uma coisa?
Obrigado.
Obrigado.
Pessoal Consegui enviar o Lote
só que eu tive que retirar essa linha do retorno
VarRecibo.Id = InnerNode.Attributes.ItemOf([Ô]Id[Ô]).InnerText
agora como faço para atualizar o XML com a autorização de Uso?
meu sistema da Nfe
PDIAS
Legal.
Vc usou alguma suite de componentes?!
Legal.
Vc usou alguma suite de componentes?!
Help
Não estou conseguindo Gravar a Autorização de Uso no XML para poder gerar o DANFE
pleasy
Não estou conseguindo Gravar a Autorização de Uso no XML para poder gerar o DANFE
pleasy
Bom retirei os erros
aparentemente os campos estão corretos
só falta gravar a autorização de uso no XML
[c] Imports System.Xml
Public Class LerXmlNFE
Public Structure NotaEletronica
Dim NotaEletronica As NFe
Dim ProtocoloAutorizacao As String
End Structure
Public Function LerNFE(ByVal CaminhoNFE As String) As NotaEletronica
Dim dados As XmlDocument = New XmlDocument
dados.Load(CaminhoNFE)
[ô]DESMEMBRA RETORNO XML
[ô]-----------------------------------------------------------------------------------
Dim NotaComProtocolo As New NotaEletronica
For Each outerNode As XmlNode In dados
If outerNode.Name = [Ô]enviNFe[Ô] Then
For Each InnerNode As XmlNode In outerNode
If InnerNode.Name = [Ô]NFe[Ô] Then
NotaComProtocolo = PegaDadosNodeNFe(InnerNode)
End If
Next
ElseIf outerNode.Name = [Ô]nfeProc[Ô] Then
For Each InnerNode As XmlNode In outerNode
If InnerNode.Name = [Ô]NFe[Ô] Then
NotaComProtocolo = PegaDadosNodeNFe(InnerNode)
End If
If InnerNode.Name = [Ô]protNFe[Ô] Then
NotaComProtocolo.ProtocoloAutorizacao = InnerNode.ChildNodes(0).ChildNodes(4).InnerText
End If
Next
ElseIf outerNode.Name = [Ô]NFe[Ô] Then
NotaComProtocolo = PegaDadosNodeNFe(outerNode)
End If
Next
Return NotaComProtocolo
Dim xmlGerado1 As XmlDocument = NotaComProtocolo.NotaEletronica.GerarXML()
[ô]Salva uma cópia do XML não assinado - ATENÇÃO - se você está utilizando Windows Vista/7/Server, salvar na Unidade C pode não ser possÃvel caso o VS2008 não esteja rodando como administrador
xmlGerado1.Save([Ô]c:\TESTELEITURA.xml[Ô])
End Function
Private Function PegaDadosNodeNFe(ByRef NodeNota As XmlNode) As NotaEletronica
Dim NotaLida As New NFe
Dim ContarDet As Integer = 0
For Each InnerNode As XmlNode In NodeNota.ChildNodes
If InnerNode.Name = [Ô]infNFe[Ô] Then
NotaLida.Id = InnerNode.Attributes.ItemOf([Ô]Id[Ô]).InnerText.Replace([Ô]NFe[Ô], [Ô][Ô])
NotaLida.versao = InnerNode.Attributes.ItemOf([Ô]versao[Ô]).InnerText
For Each InnerNode2 As XmlNode In InnerNode.ChildNodes
If (InnerNode2.Name = [Ô]ide[Ô]) Then
Dim ContarEntradas As Integer = 0
NotaLida.infNFE.Ide.cUF = InnerNode2.ChildNodes(0).InnerText
NotaLida.infNFE.Ide.cNF = InnerNode2.ChildNodes(1).InnerText
NotaLida.infNFE.Ide.natOp = InnerNode2.ChildNodes(2).InnerText
NotaLida.infNFE.Ide.indPag = InnerNode2.ChildNodes(3).InnerText
NotaLida.infNFE.Ide.[mod] = InnerNode2.ChildNodes(4).InnerText
NotaLida.infNFE.Ide.serie = InnerNode2.ChildNodes(5).InnerText
NotaLida.infNFE.Ide.nNF = InnerNode2.ChildNodes(6).InnerText
NotaLida.infNFE.Ide.dEmi = InnerNode2.ChildNodes(7).InnerText
If InnerNode2.ChildNodes(8).Name = [Ô]dEmi[Ô] Then
NotaLida.infNFE.Ide.dEmi = InnerNode2.ChildNodes(8).InnerText
NotaLida.infNFE.Ide.dSaiEnt = InnerNode2.ChildNodes(9).InnerText
NotaLida.infNFE.Ide.tpNF = InnerNode2.ChildNodes(10).InnerText
NotaLida.infNFE.Ide.cMunFG = InnerNode2.ChildNodes(11).InnerText
Else
NotaLida.infNFE.Ide.dSaiEnt = InnerNode2.ChildNodes(7).InnerText
NotaLida.infNFE.Ide.tpNF = InnerNode2.ChildNodes(10).InnerText
NotaLida.infNFE.Ide.cMunFG = InnerNode2.ChildNodes(11).InnerText
[ô]ContarEntradas -= 1
End If
For Each InnerNode3 As XmlNode In InnerNode2.ChildNodes
If InnerNode3.Name = [Ô]NFref[Ô] Then
Dim NFrefS As NFref
If InnerNode3.ChildNodes(0).Name = [Ô]refNFe[Ô] Then
NFrefS = New NFref
NFrefS.refNFe = InnerNode3.ChildNodes(0).ChildNodes(0).InnerText
NotaLida.infNFE.Ide.NFRef.Add(NFrefS)
Else
NFrefS = New NFref
NFrefS.RefNF.cUF = InnerNode3.ChildNodes(0).ChildNodes(0).InnerText
NFrefS.RefNF.AAMM = InnerNode3.ChildNodes(0).ChildNodes(1).InnerText
NFrefS.RefNF.CNPJ = InnerNode3.ChildNodes(0).ChildNodes(2).InnerText
NFrefS.RefNF.mod = InnerNode3.ChildNodes(0).ChildNodes(3).InnerText
NFrefS.RefNF.serie = InnerNode3.ChildNodes(0).ChildNodes(4).InnerText
NFrefS.RefNF.nNF = InnerNode3.ChildNodes(0).ChildNodes(5).InnerText
NotaLida.infNFE.Ide.NFRef.Add(NFrefS)
End If
ContarEntradas += 1
End If
Next
NotaLida.infNFE.Ide.tpImp = InnerNode2.ChildNodes(11 + ContarEntradas).InnerText
NotaLida.infNFE.Ide.tpEmis = InnerNode2.ChildNodes(12 + ContarEntradas).InnerText
NotaLida.infNFE.Ide.cDV = InnerNode2.ChildNodes(13 + ContarEntradas).InnerText
NotaLida.infNFE.Ide.tpAmb = InnerNode2.ChildNodes(14 + ContarEntradas).InnerText
NotaLida.infNFE.Ide.finNFe = InnerNode2.ChildNodes(15 + ContarEntradas).InnerText
NotaLida.infNFE.Ide.procEmi = InnerNode2.ChildNodes(16 + ContarEntradas).InnerText
NotaLida.infNFE.Ide.verProc = InnerNode2.ChildNodes(16 + ContarEntradas).InnerText
ElseIf (InnerNode2.Name = [Ô]emit[Ô]) Then
NotaLida.infNFE.Emit.CNPJ = InnerNode2.ChildNodes(0).InnerText
NotaLida.infNFE.Emit.xNome = InnerNode2.ChildNodes(1).InnerText
NotaLida.infNFE.Emit.xFant = InnerNode2.ChildNodes(2).InnerText
NotaLida.infNFE.Emit.EnderEmit.xLgr = InnerNode2.ChildNodes(3).ChildNodes(0).InnerText
NotaLida.infNFE.Emit.EnderEmit.nro = InnerNode2.ChildNodes(3).ChildNodes(1).InnerText
NotaLida.infNFE.Emit.EnderEmit.xBairro = InnerNode2.ChildNodes(3).ChildNodes(2).InnerText
NotaLida.infNFE.Emit.EnderEmit.cMun = InnerNode2.ChildNodes(3).ChildNodes(3).InnerText
NotaLida.infNFE.Emit.EnderEmit.xMun = InnerNode2.ChildNodes(3).ChildNodes(4).InnerText
NotaLida.infNFE.Emit.EnderEmit.UF = InnerNode2.ChildNodes(3).ChildNodes(5).InnerText
NotaLida.infNFE.Emit.EnderEmit.CEP = InnerNode2.ChildNodes(3).ChildNodes(6).InnerText
NotaLida.infNFE.Emit.EnderEmit.cPais = InnerNode2.ChildNodes(3).ChildNodes(7).InnerText
NotaLida.infNFE.Emit.EnderEmit.xPais = InnerNode2.ChildNodes(3).ChildNodes(8).InnerText
NotaLida.infNFE.Emit.EnderEmit.fone = InnerNode2.ChildNodes(3).ChildNodes(9).InnerText
NotaLida.infNFE.Emit.IE = InnerNode2.ChildNodes(4).InnerText
ElseIf (InnerNode2.Name = [Ô]dest[Ô]) Then
NotaLida.infNFE.Dest.CNPJ = InnerNode2.ChildNodes(0).InnerText
NotaLida.infNFE.Dest.xNome = InnerNode2.ChildNodes(1).InnerText
NotaLida.infNFE.Dest.EnderDest.xLgr = InnerNode2.ChildNodes(2).ChildNodes(0).InnerText
NotaLida.infNFE.Dest.EnderDest.nro = InnerNode2.ChildNodes(2).ChildNodes(1).InnerText
NotaLida.infNFE.Dest.EnderDest.xBairro = InnerNode2.ChildNodes(2).ChildNodes(2).InnerText
NotaLida.infNFE.Dest.EnderDest.cMun = InnerNode2.ChildNodes(2).ChildNodes(3).InnerText
NotaLida.infNFE.Dest.EnderDest.xMun = InnerNode2.ChildNodes(2).ChildNodes(4).InnerText
NotaLida.infNFE.Dest.EnderDest.UF = InnerNode2.ChildNodes(2).ChildNodes(5).InnerText
If InnerNode2.ChildNodes(2).ChildNodes(6).Name = [Ô]CEP[Ô] Then
NotaLida.infNFE.Dest.EnderDest.CEP = InnerNode2.ChildNodes(2).ChildNodes(6).InnerText
NotaLida.infNFE.Dest.EnderDest.cPais = InnerNode2.ChildNodes(2).ChildNodes(7).InnerText
NotaLida.infNFE.Dest.EnderDest.xPais = InnerNode2.ChildNodes(2).ChildNodes(8).InnerText
Try
If InnerNode2.ChildNodes(2).ChildNodes(9).Name = [Ô]fone[Ô] Then
NotaLida.infNFE.Dest.EnderDest.fone = InnerNode2.ChildNodes(2).ChildNodes(9).InnerText
End If
Catch
NotaLida.infNFE.Dest.EnderDest.fone = [Ô][Ô]
Finally
End Try
Else
NotaLida.infNFE.Dest.EnderDest.cPais = InnerNode2.ChildNodes(2).ChildNodes(6).InnerText
NotaLida.infNFE.Dest.EnderDest.xPais = InnerNode2.ChildNodes(2).ChildNodes(7).InnerText
Try
If InnerNode2.ChildNodes(2).ChildNodes(8).Name = [Ô]fone[Ô] Then
aparentemente os campos estão corretos
só falta gravar a autorização de uso no XML
[c] Imports System.Xml
Public Class LerXmlNFE
Public Structure NotaEletronica
Dim NotaEletronica As NFe
Dim ProtocoloAutorizacao As String
End Structure
Public Function LerNFE(ByVal CaminhoNFE As String) As NotaEletronica
Dim dados As XmlDocument = New XmlDocument
dados.Load(CaminhoNFE)
[ô]DESMEMBRA RETORNO XML
[ô]-----------------------------------------------------------------------------------
Dim NotaComProtocolo As New NotaEletronica
For Each outerNode As XmlNode In dados
If outerNode.Name = [Ô]enviNFe[Ô] Then
For Each InnerNode As XmlNode In outerNode
If InnerNode.Name = [Ô]NFe[Ô] Then
NotaComProtocolo = PegaDadosNodeNFe(InnerNode)
End If
Next
ElseIf outerNode.Name = [Ô]nfeProc[Ô] Then
For Each InnerNode As XmlNode In outerNode
If InnerNode.Name = [Ô]NFe[Ô] Then
NotaComProtocolo = PegaDadosNodeNFe(InnerNode)
End If
If InnerNode.Name = [Ô]protNFe[Ô] Then
NotaComProtocolo.ProtocoloAutorizacao = InnerNode.ChildNodes(0).ChildNodes(4).InnerText
End If
Next
ElseIf outerNode.Name = [Ô]NFe[Ô] Then
NotaComProtocolo = PegaDadosNodeNFe(outerNode)
End If
Next
Return NotaComProtocolo
Dim xmlGerado1 As XmlDocument = NotaComProtocolo.NotaEletronica.GerarXML()
[ô]Salva uma cópia do XML não assinado - ATENÇÃO - se você está utilizando Windows Vista/7/Server, salvar na Unidade C pode não ser possÃvel caso o VS2008 não esteja rodando como administrador
xmlGerado1.Save([Ô]c:\TESTELEITURA.xml[Ô])
End Function
Private Function PegaDadosNodeNFe(ByRef NodeNota As XmlNode) As NotaEletronica
Dim NotaLida As New NFe
Dim ContarDet As Integer = 0
For Each InnerNode As XmlNode In NodeNota.ChildNodes
If InnerNode.Name = [Ô]infNFe[Ô] Then
NotaLida.Id = InnerNode.Attributes.ItemOf([Ô]Id[Ô]).InnerText.Replace([Ô]NFe[Ô], [Ô][Ô])
NotaLida.versao = InnerNode.Attributes.ItemOf([Ô]versao[Ô]).InnerText
For Each InnerNode2 As XmlNode In InnerNode.ChildNodes
If (InnerNode2.Name = [Ô]ide[Ô]) Then
Dim ContarEntradas As Integer = 0
NotaLida.infNFE.Ide.cUF = InnerNode2.ChildNodes(0).InnerText
NotaLida.infNFE.Ide.cNF = InnerNode2.ChildNodes(1).InnerText
NotaLida.infNFE.Ide.natOp = InnerNode2.ChildNodes(2).InnerText
NotaLida.infNFE.Ide.indPag = InnerNode2.ChildNodes(3).InnerText
NotaLida.infNFE.Ide.[mod] = InnerNode2.ChildNodes(4).InnerText
NotaLida.infNFE.Ide.serie = InnerNode2.ChildNodes(5).InnerText
NotaLida.infNFE.Ide.nNF = InnerNode2.ChildNodes(6).InnerText
NotaLida.infNFE.Ide.dEmi = InnerNode2.ChildNodes(7).InnerText
If InnerNode2.ChildNodes(8).Name = [Ô]dEmi[Ô] Then
NotaLida.infNFE.Ide.dEmi = InnerNode2.ChildNodes(8).InnerText
NotaLida.infNFE.Ide.dSaiEnt = InnerNode2.ChildNodes(9).InnerText
NotaLida.infNFE.Ide.tpNF = InnerNode2.ChildNodes(10).InnerText
NotaLida.infNFE.Ide.cMunFG = InnerNode2.ChildNodes(11).InnerText
Else
NotaLida.infNFE.Ide.dSaiEnt = InnerNode2.ChildNodes(7).InnerText
NotaLida.infNFE.Ide.tpNF = InnerNode2.ChildNodes(10).InnerText
NotaLida.infNFE.Ide.cMunFG = InnerNode2.ChildNodes(11).InnerText
[ô]ContarEntradas -= 1
End If
For Each InnerNode3 As XmlNode In InnerNode2.ChildNodes
If InnerNode3.Name = [Ô]NFref[Ô] Then
Dim NFrefS As NFref
If InnerNode3.ChildNodes(0).Name = [Ô]refNFe[Ô] Then
NFrefS = New NFref
NFrefS.refNFe = InnerNode3.ChildNodes(0).ChildNodes(0).InnerText
NotaLida.infNFE.Ide.NFRef.Add(NFrefS)
Else
NFrefS = New NFref
NFrefS.RefNF.cUF = InnerNode3.ChildNodes(0).ChildNodes(0).InnerText
NFrefS.RefNF.AAMM = InnerNode3.ChildNodes(0).ChildNodes(1).InnerText
NFrefS.RefNF.CNPJ = InnerNode3.ChildNodes(0).ChildNodes(2).InnerText
NFrefS.RefNF.mod = InnerNode3.ChildNodes(0).ChildNodes(3).InnerText
NFrefS.RefNF.serie = InnerNode3.ChildNodes(0).ChildNodes(4).InnerText
NFrefS.RefNF.nNF = InnerNode3.ChildNodes(0).ChildNodes(5).InnerText
NotaLida.infNFE.Ide.NFRef.Add(NFrefS)
End If
ContarEntradas += 1
End If
Next
NotaLida.infNFE.Ide.tpImp = InnerNode2.ChildNodes(11 + ContarEntradas).InnerText
NotaLida.infNFE.Ide.tpEmis = InnerNode2.ChildNodes(12 + ContarEntradas).InnerText
NotaLida.infNFE.Ide.cDV = InnerNode2.ChildNodes(13 + ContarEntradas).InnerText
NotaLida.infNFE.Ide.tpAmb = InnerNode2.ChildNodes(14 + ContarEntradas).InnerText
NotaLida.infNFE.Ide.finNFe = InnerNode2.ChildNodes(15 + ContarEntradas).InnerText
NotaLida.infNFE.Ide.procEmi = InnerNode2.ChildNodes(16 + ContarEntradas).InnerText
NotaLida.infNFE.Ide.verProc = InnerNode2.ChildNodes(16 + ContarEntradas).InnerText
ElseIf (InnerNode2.Name = [Ô]emit[Ô]) Then
NotaLida.infNFE.Emit.CNPJ = InnerNode2.ChildNodes(0).InnerText
NotaLida.infNFE.Emit.xNome = InnerNode2.ChildNodes(1).InnerText
NotaLida.infNFE.Emit.xFant = InnerNode2.ChildNodes(2).InnerText
NotaLida.infNFE.Emit.EnderEmit.xLgr = InnerNode2.ChildNodes(3).ChildNodes(0).InnerText
NotaLida.infNFE.Emit.EnderEmit.nro = InnerNode2.ChildNodes(3).ChildNodes(1).InnerText
NotaLida.infNFE.Emit.EnderEmit.xBairro = InnerNode2.ChildNodes(3).ChildNodes(2).InnerText
NotaLida.infNFE.Emit.EnderEmit.cMun = InnerNode2.ChildNodes(3).ChildNodes(3).InnerText
NotaLida.infNFE.Emit.EnderEmit.xMun = InnerNode2.ChildNodes(3).ChildNodes(4).InnerText
NotaLida.infNFE.Emit.EnderEmit.UF = InnerNode2.ChildNodes(3).ChildNodes(5).InnerText
NotaLida.infNFE.Emit.EnderEmit.CEP = InnerNode2.ChildNodes(3).ChildNodes(6).InnerText
NotaLida.infNFE.Emit.EnderEmit.cPais = InnerNode2.ChildNodes(3).ChildNodes(7).InnerText
NotaLida.infNFE.Emit.EnderEmit.xPais = InnerNode2.ChildNodes(3).ChildNodes(8).InnerText
NotaLida.infNFE.Emit.EnderEmit.fone = InnerNode2.ChildNodes(3).ChildNodes(9).InnerText
NotaLida.infNFE.Emit.IE = InnerNode2.ChildNodes(4).InnerText
ElseIf (InnerNode2.Name = [Ô]dest[Ô]) Then
NotaLida.infNFE.Dest.CNPJ = InnerNode2.ChildNodes(0).InnerText
NotaLida.infNFE.Dest.xNome = InnerNode2.ChildNodes(1).InnerText
NotaLida.infNFE.Dest.EnderDest.xLgr = InnerNode2.ChildNodes(2).ChildNodes(0).InnerText
NotaLida.infNFE.Dest.EnderDest.nro = InnerNode2.ChildNodes(2).ChildNodes(1).InnerText
NotaLida.infNFE.Dest.EnderDest.xBairro = InnerNode2.ChildNodes(2).ChildNodes(2).InnerText
NotaLida.infNFE.Dest.EnderDest.cMun = InnerNode2.ChildNodes(2).ChildNodes(3).InnerText
NotaLida.infNFE.Dest.EnderDest.xMun = InnerNode2.ChildNodes(2).ChildNodes(4).InnerText
NotaLida.infNFE.Dest.EnderDest.UF = InnerNode2.ChildNodes(2).ChildNodes(5).InnerText
If InnerNode2.ChildNodes(2).ChildNodes(6).Name = [Ô]CEP[Ô] Then
NotaLida.infNFE.Dest.EnderDest.CEP = InnerNode2.ChildNodes(2).ChildNodes(6).InnerText
NotaLida.infNFE.Dest.EnderDest.cPais = InnerNode2.ChildNodes(2).ChildNodes(7).InnerText
NotaLida.infNFE.Dest.EnderDest.xPais = InnerNode2.ChildNodes(2).ChildNodes(8).InnerText
Try
If InnerNode2.ChildNodes(2).ChildNodes(9).Name = [Ô]fone[Ô] Then
NotaLida.infNFE.Dest.EnderDest.fone = InnerNode2.ChildNodes(2).ChildNodes(9).InnerText
End If
Catch
NotaLida.infNFE.Dest.EnderDest.fone = [Ô][Ô]
Finally
End Try
Else
NotaLida.infNFE.Dest.EnderDest.cPais = InnerNode2.ChildNodes(2).ChildNodes(6).InnerText
NotaLida.infNFE.Dest.EnderDest.xPais = InnerNode2.ChildNodes(2).ChildNodes(7).InnerText
Try
If InnerNode2.ChildNodes(2).ChildNodes(8).Name = [Ô]fone[Ô] Then
Estou com uma duvida
qual a rotina correta para usar este exemplo
1 gerar XML
2 Enviar XML
3?
4 imprime DANFE
em 3 eu uso o Ler XML ou Consultar XML
qual a rotina correta para usar este exemplo
1 gerar XML
2 Enviar XML
3?
4 imprime DANFE
em 3 eu uso o Ler XML ou Consultar XML
1 gerar XML
2 Enviar XML (O enviar já consulta)
3 Ler Xml
4 imprime DANFE
2 Enviar XML (O enviar já consulta)
3 Ler Xml
4 imprime DANFE
Citação::
1 gerar XML
2 Enviar XML (O enviar já consulta)
3 Ler Xml
4 imprime DANFE
Daniel Eu executo o Ler XML
Mais como que eu atualizo o XML com a autorização de Uso do Sefa
na Rotina LerXml?
Citação::
:
1 gerar XML
2 Enviar XML (O enviar já consulta)
3 Ler Xml
4 imprime DANFE
Daniel Eu executo o Ler XML
Mais como que eu atualizo o XML com a autorização de Uso do Sefa
na Rotina LerXml?
MFlavio,
Você terá que gerar um XML da seguinte forma:
<?xml version=[Ô]1.0[Ô] encoding=[Ô]utf-8[Ô] ?>
<nfeProc versao=[Ô]2.00[Ô] 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[Ô]>
<NFe xmlns=[Ô]http://www.portalfiscal.inf.br/nfe[Ô]>
...conteudo do XML que você transmitiu e recebeu autorização...
</NFe>
<protNFe versao=[Ô]2.00[Ô]>
<infProt xmlns=[Ô]http://www.portalfiscal.inf.br/nfe[Ô]>
...conteudo_da_tag_infProt_que_você_recebeu_da_sefaz
</infProt>
</protNFe>
</nfeProc>
Faça seu login para responder