Esempio n. 1
0
        public string EnviarLoteRpsEnvio(XmlDocument xmlLote) 
        {
            try
            {
                string sMesssage = "";
                if (belStatic.tpAmbNFse == 1) // Produção
                {
                    HLP.WebService.Itu_servicos_Producao.ServiceGinfesImplService objWebServices = new HLP.WebService.Itu_servicos_Producao.ServiceGinfesImplService();
                    AssinaNFeXml objbuscanome = new AssinaNFeXml();
                    X509Certificate2 cert = new X509Certificate2();
                    cert = objbuscanome.BuscaNome("");
                    objWebServices.ClientCertificates.Add(cert);
                }
                else//Homologação
                {
                    HLP.WebService.Itu_servicos_Homologacao.ServiceGinfesImplService objWebServices = new HLP.WebService.Itu_servicos_Homologacao.ServiceGinfesImplService();

                }
               

               

                    



                return sMesssage;
            }
            catch (Exception)
            {                
                throw;
            }
           
        }
Esempio n. 2
0
        public void GerarAqruivoXml(tcLoteRps objLoteRpd)
        {
            try
            {
                List<string> ListaNfes = new List<string>();
                Globais glob = new Globais();
                XDocument xdoc = new XDocument();
                XNamespace tns = "http://www.ginfes.com.br/servico_enviar_lote_rps_envio";
                XNamespace tipos = "http://www.ginfes.com.br/tipos_v03.xsd";
                XNamespace ds = "http://www.w3.org/2000/09/xmldsig#";
                XNamespace xsi = "http://www.w3.org/2001/XMLSchema-instance";
                XNamespace n1 = "http://www.altova.com/samplexml/other-namespace";
                XNamespace pf = "http://www.ginfes.com.br/servico_enviar_lote_rps_envio_v03.xsd";


                XContainer conEnviarLoteRpsEnvio = (new XElement(pf + "EnviarLoteRpsEnvio", new XAttribute("xmlns", "http://www.ginfes.com.br/servico_enviar_lote_rps_envio_v03.xsd")));

                XContainer conLoteRps = (new XElement(pf + "LoteRps", new XAttribute("Id", objLoteRpd.NumeroLote),
                                                                new XAttribute(XNamespace.Xmlns + "tipos", "http://www.ginfes.com.br/tipos_v03.xsd"),
                                                                                     new XElement(tipos + "NumeroLote", objLoteRpd.NumeroLote.ToString()),
                                                                                     new XElement(tipos + "Cnpj", objLoteRpd.Cnpj.ToString()),
                                                                                     new XElement(tipos + "InscricaoMunicipal", objLoteRpd.InscricaoMunicipal.ToString()),
                                                                                     new XElement(tipos + "QuantidadeRps", objLoteRpd.QuantidadeRps.ToString())));

                XContainer conListaRps = (new XElement(tipos + "ListaRps"));
                XContainer conRps = (new XElement(tipos + "Rps"));
                XContainer conInfRps = null;
                XContainer conSubstituto = null;
                XContainer conServico = null;
                XContainer conPrestador = null;
                XContainer conTomador = null;
                XContainer conIntermediarioServico = null;
                XContainer conConstrucaoCivil = null;
                AssinaNFeXml Assinatura = new AssinaNFeXml();

                foreach (TcRps rps in objLoteRpd.Rps)
                {
                    #region IdentificacaoRps conRps
                    try
                    {
                        conInfRps = (new XElement(tipos + "InfRps", new XElement(tipos + "IdentificacaoRps",
                                                                                     new XElement(tipos + "Numero", rps.InfRps.IdentificacaoRps.Numero),
                                                                                     new XElement(tipos + "Serie", rps.InfRps.IdentificacaoRps.Serie),
                                                                                     new XElement(tipos + "Tipo", rps.InfRps.IdentificacaoRps.Tipo)),
                                                                          new XElement(tipos + "DataEmissao", HLP.Util.Util.GetDateServidor().Date.ToString("yyyy-MM-ddTHH:mm:ss")),
                                                                          new XElement(tipos + "NaturezaOperacao", rps.InfRps.NaturezaOperacao),
                                                                         ((rps.InfRps.RegimeEspecialTributacao != 0) ? new XElement(tipos + "RegimeEspecialTributacao", rps.InfRps.RegimeEspecialTributacao) : null),
                                                                          new XElement(tipos + "OptanteSimplesNacional", rps.InfRps.OptanteSimplesNacional),
                                                                          new XElement(tipos + "IncentivadorCultural", rps.InfRps.IncentivadorCultural),
                                                                          new XElement(tipos + "Status", rps.InfRps.Status)));

                    }
                    catch (Exception x)
                    {
                        throw new Exception("Nota : " + rps.InfRps.IdentificacaoRps.Numero + "Erro na geração do XML, Regiao:('IdentificacaoRps')- "
                            + Environment.NewLine + "XML_Detalhes: "
                            + Environment.NewLine + x.Message);
                    }
                    #endregion

                    #region RpsSubstituido
                    if (rps.InfRps.RpsSubstituido != null)
                    {
                        try
                        {
                            conSubstituto = (new XElement(tipos + "RpsSubstituido",
                                                         new XElement(tipos + "Numero", rps.InfRps.RpsSubstituido.Numero),
                                                         new XElement(tipos + "Serie", rps.InfRps.RpsSubstituido.Serie),
                                                         new XElement(tipos + "Tipo", rps.InfRps.RpsSubstituido.Tipo)));
                        }
                        catch (Exception x)
                        {
                            throw new Exception("Nota : " + rps.InfRps.IdentificacaoRps.Numero + "Erro na geração do XML, Regiao:('RpsSubstituido')- "
                                + Environment.NewLine + "XML_Detalhes: "
                                + Environment.NewLine + x.Message);
                        }
                    }

                    #endregion

                    #region Servico
                    try
                    {
                        conServico = (new XElement(tipos + "Servico", new XElement(tipos + "Valores",
                                                    new XElement(tipos + "ValorServicos", rps.InfRps.Servico.Valores.ValorServicos.ToString("#0.00").Replace(",", ".")),
                                                    ((rps.InfRps.Servico.Valores.ValorDeducoes > 0) ? new XElement(tipos + "ValorDeducoes", rps.InfRps.Servico.Valores.ValorDeducoes.ToString("#0.00").Replace(",", ".")) : null),
                                                    ((rps.InfRps.Servico.Valores.ValorPis > 0) ? new XElement(tipos + "ValorPis", rps.InfRps.Servico.Valores.ValorPis.ToString("#0.00").Replace(",", ".")) : null),
                                                    ((rps.InfRps.Servico.Valores.ValorCofins > 0) ? new XElement(tipos + "ValorCofins", rps.InfRps.Servico.Valores.ValorCofins.ToString("#0.00").Replace(",", ".")) : null),
                                                    ((rps.InfRps.Servico.Valores.ValorInss > 0) ? new XElement(tipos + "ValorInss", rps.InfRps.Servico.Valores.ValorInss.ToString("#0.00").Replace(",", ".")) : null),
                                                    ((rps.InfRps.Servico.Valores.ValorIr > 0) ? new XElement(tipos + "ValorIr", rps.InfRps.Servico.Valores.ValorIr.ToString("#0.00").Replace(",", ".")) : null),
                                                    ((rps.InfRps.Servico.Valores.ValorCsll > 0) ? new XElement(tipos + "ValorCsll", rps.InfRps.Servico.Valores.ValorCsll.ToString("#0.00").Replace(",", ".")) : null),
                                                                                                      new XElement(tipos + "IssRetido", rps.InfRps.Servico.Valores.IssRetido),
                                                    ((rps.InfRps.Servico.Valores.ValorIss > 0) ? new XElement(tipos + "ValorIss", rps.InfRps.Servico.Valores.ValorIss.ToString("#0.00").Replace(",", ".")) : null),
                                                    ((rps.InfRps.Servico.Valores.ValorIssRetido > 0) ? new XElement(tipos + "ValorIssRetido", rps.InfRps.Servico.Valores.ValorIssRetido.ToString("#0.00").Replace(",", ".")) : null),
                                                    ((rps.InfRps.Servico.Valores.OutrasRetencoes > 0) ? new XElement(tipos + "OutrasRetencoes", rps.InfRps.Servico.Valores.OutrasRetencoes.ToString("#0.00").Replace(",", ".")) : null),
                                                    ((rps.InfRps.Servico.Valores.BaseCalculo > 0) ? new XElement(tipos + "BaseCalculo", rps.InfRps.Servico.Valores.BaseCalculo.ToString("#0.00").Replace(",", ".")) : null),
                                                    ((rps.InfRps.Servico.Valores.Aliquota > 0) ? new XElement(tipos + "Aliquota", (rps.InfRps.Servico.Valores.Aliquota / 100).ToString("#0.0000").Replace(",", ".")) : null),
                                                    ((rps.InfRps.Servico.Valores.ValorLiquidoNfse > 0) ? new XElement(tipos + "ValorLiquidoNfse", rps.InfRps.Servico.Valores.ValorLiquidoNfse.ToString("#0.00").Replace(",", ".")) : null),
                                                    ((rps.InfRps.Servico.Valores.DescontoCondicionado > 0) ? new XElement(tipos + "DescontoCondicionado", rps.InfRps.Servico.Valores.DescontoCondicionado.ToString("#0.00").Replace(",", ".")) : null),
                                                    ((rps.InfRps.Servico.Valores.DescontoIncondicionado > 0) ? new XElement(tipos + "DescontoIncondicionado", rps.InfRps.Servico.Valores.DescontoIncondicionado.ToString("#0.00").Replace(",", ".")) : null)),
                                                                                         new XElement(tipos + "ItemListaServico", rps.InfRps.Servico.ItemListaServico),
                                       ((rps.InfRps.Servico.CodigoCnae != "") ? new XElement(tipos + "CodigoCnae", rps.InfRps.Servico.CodigoCnae) : null),
                                       (((rps.InfRps.Servico.CodigoTributacaoMunicipio != "") && (rps.InfRps.Servico.CodigoTributacaoMunicipio != "0")) ? new XElement(tipos + "CodigoTributacaoMunicipio", rps.InfRps.Servico.CodigoTributacaoMunicipio) : null),
                                                                                         new XElement(tipos + "Discriminacao", rps.InfRps.Servico.Discriminacao),
                                       new XElement(tipos + "CodigoMunicipio", rps.InfRps.Servico.CodigoMunicipio)));
                    }
                    catch (Exception x)
                    {
                        throw new Exception("Nota : " + rps.InfRps.IdentificacaoRps.Numero + "Erro na geração do XML, Regiao:('Servico')- "
                            + Environment.NewLine + "XML_Detalhes: "
                            + Environment.NewLine + x.Message);
                    }
                    #endregion

                    #region Prestador
                    try
                    {
                        conPrestador = (new XElement(tipos + "Prestador", new XElement(tipos + "Cnpj", rps.InfRps.Prestador.Cnpj),
                                                                      ((rps.InfRps.Prestador.InscricaoMunicipal != "") ? new XElement(tipos + "InscricaoMunicipal", rps.InfRps.Prestador.InscricaoMunicipal) : null)));

                    }
                    catch (Exception x)
                    {
                        throw new Exception("Nota : " + rps.InfRps.IdentificacaoRps.Numero + "Erro na geração do XML, Regiao:('Prestador')- "
                            + Environment.NewLine + "XML_Detalhes: "
                            + Environment.NewLine + x.Message);
                    }
                    #endregion

                    #region Tomador
                    try
                    {
                        conTomador = (new XElement(tipos + "Tomador", ((rps.InfRps.Tomador.IdentificacaoTomador != null) ? new XElement(tipos + "IdentificacaoTomador", new XElement(tipos + "CpfCnpj",
                                                                                                               new XElement(tipos + (rps.InfRps.Tomador.IdentificacaoTomador.CpfCnpj.Cnpj != "" ? "Cnpj" : "Cpf"), (rps.InfRps.Tomador.IdentificacaoTomador.CpfCnpj.Cnpj != "" ? rps.InfRps.Tomador.IdentificacaoTomador.CpfCnpj.Cnpj : rps.InfRps.Tomador.IdentificacaoTomador.CpfCnpj.Cpf))),
                                                                    (rps.InfRps.Tomador.IdentificacaoTomador.InscricaoMunicipal != "" ? (new XElement(tipos + "InscricaoMunicipal", rps.InfRps.Tomador.IdentificacaoTomador.InscricaoMunicipal)) : null)) : null),
                                                                    new XElement(tipos + "RazaoSocial", rps.InfRps.Tomador.RazaoSocial),
                                                                    new XElement(tipos + "Endereco",
                                                                                       new XElement(tipos + "Endereco", rps.InfRps.Tomador.Endereco.Endereco),
                                                                                       new XElement(tipos + "Numero", rps.InfRps.Tomador.Endereco.Numero),
                                                                                      (rps.InfRps.Tomador.Endereco.Complemento != "" ? new XElement(tipos + "Complemento", rps.InfRps.Tomador.Endereco.Complemento) : null),
                                                                                       new XElement(tipos + "Bairro", rps.InfRps.Tomador.Endereco.Bairro),
                                                                                       new XElement(tipos + "CodigoMunicipio", rps.InfRps.Tomador.Endereco.CodigoMunicipio),
                                                                                       new XElement(tipos + "Uf", rps.InfRps.Tomador.Endereco.Uf),
                                                                                       new XElement(tipos + "Cep", rps.InfRps.Tomador.Endereco.Cep))));


                    }
                    catch (Exception x)
                    {
                        throw new Exception("Nota : " + rps.InfRps.IdentificacaoRps.Numero + "Erro na geração do XML, Regiao:('Tomador')- "
                            + Environment.NewLine + "XML_Detalhes: "
                            + Environment.NewLine + x.Message);
                    }

                    #endregion

                    #region IntermediarioServico
                    try
                    {
                        if (rps.InfRps.IntermediarioServico != null)
                        {
                            conIntermediarioServico = (new XElement(tipos + "IntermediarioServico", new XElement(tipos + "RazaoSocial", rps.InfRps.IntermediarioServico.RazaoSocial),
                                                                                               new XElement(tipos + "CpfCnpj", (new XElement(tipos + (rps.InfRps.IntermediarioServico.CpfCnpj.Cnpj != null ? "Cnpj" : "Cpf"), (rps.InfRps.IntermediarioServico.CpfCnpj.Cnpj != null ? rps.InfRps.IntermediarioServico.CpfCnpj.Cnpj : rps.InfRps.IntermediarioServico.CpfCnpj.Cpf)))),
                                                                                               new XElement(tipos + "InscricaoMunicipal", rps.InfRps.IntermediarioServico.InscricaoMunicipal)));
                        }
                    }
                    catch (Exception x)
                    {
                        throw new Exception("Nota : " + rps.InfRps.IdentificacaoRps.Numero + "Erro na geração do XML, Regiao:('IntermediarioServico')- "
                            + Environment.NewLine + "XML_Detalhes: "
                            + Environment.NewLine + x.Message);
                    }
                    #endregion

                    #region ConstrucaoCivil

                    try
                    {
                        if (rps.InfRps.ConstrucaoCivil != null)
                        {
                            if ((rps.InfRps.ConstrucaoCivil.CodigoObra != "") && (rps.InfRps.ConstrucaoCivil.Art != ""))
                            {
                                conConstrucaoCivil = (new XElement(tipos + "ConstrucaoCivil", new XElement(tipos + "CodigoObra", rps.InfRps.ConstrucaoCivil.CodigoObra),
                                                                                          new XElement(tipos + "Art", rps.InfRps.ConstrucaoCivil.Art)));
                            }
                        }

                    }
                    catch (Exception x)
                    {
                        throw new Exception("Nota : " + rps.InfRps.IdentificacaoRps.Numero + "Erro na geração do XML, Regiao:('ConstrucaoCivil')- "
                            + Environment.NewLine + "XML_Detalhes: "
                            + Environment.NewLine + x.Message);
                    }
                    #endregion

                    try
                    {
                        if (conSubstituto != null)
                        {
                            conInfRps.Add(conSubstituto);
                        }
                        conInfRps.Add(conServico);
                        conInfRps.Add(conPrestador);
                        conInfRps.Add(conTomador);
                        if (conIntermediarioServico != null) { conInfRps.Add(conIntermediarioServico); }
                        if (conConstrucaoCivil != null) { conInfRps.Add(conConstrucaoCivil); }
                        conRps.Add(conInfRps);

                        // string nfe = Assinatura.ConfigurarArquivo(conRps.ToString(), "InfRps", cert);
                        // XmlDocument xml = new XmlDocument();
                        // xml.LoadXml(nfe);
                        //  conListaRps.Add(xml);
                        conListaRps.Add(conRps);


                        //Salva o Rps;
                        XDocument xdocsalvanfesemlot = new XDocument(conRps);
                        string sPasta = rps.InfRps.DataEmissao.ToString("MM/yy").Replace("/", "");
                        string sNomeArquivo = rps.InfRps.DataEmissao.ToString("MM/yy").Replace("/", "") + rps.InfRps.IdentificacaoRps.Serie + rps.InfRps.IdentificacaoRps.Numero;
                        DirectoryInfo dPastaData = new DirectoryInfo(belStaticPastas.ENVIO + "\\Servicos\\" + sPasta);
                        if (!dPastaData.Exists) { dPastaData.Create(); }
                        xdocsalvanfesemlot.Save(belStaticPastas.ENVIO + "\\Servicos\\" + sPasta + "\\" + sNomeArquivo + "-nfes.xml");

                        conRps = (new XElement(tipos + "Rps"));
                    }
                    catch (Exception x)
                    {
                        throw new Exception("Nota de Sequência - " + "sNota" + "Erro ao assinar a nfe de sequencia " + "sNota" + x.Message);
                    }
                }

                conLoteRps.Add(conListaRps);
                conEnviarLoteRpsEnvio.Add(conLoteRps);
                //Assina Arquivo
                string nfes = Assinatura.ConfigurarArquivo(conEnviarLoteRpsEnvio.ToString(), "LoteRps", cert);
                sXmlLote = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + nfes;
                //Grava
                string sPathLote = belStaticPastas.ENVIO + "\\Servicos\\" + "Lote_" + objLoteRpd.NumeroLote + ".xml";
                StreamWriter sw = new StreamWriter(sPathLote);
                sw.Write(sXmlLote);
                sw.Close();

                #region Valida_Xml|

                Globais getschema = new Globais();
                XmlSchemaCollection myschema = new XmlSchemaCollection();
                XmlValidatingReader reader;
                try
                {
                    XmlParserContext context = new XmlParserContext(null, null, "", XmlSpace.None);
                    reader = new XmlValidatingReader(sXmlLote, XmlNodeType.Element, context);
                    myschema.Add("http://www.ginfes.com.br/servico_enviar_lote_rps_envio_v03.xsd", belStaticPastas.SCHEMA_NFSE + "\\servico_enviar_lote_rps_envio_v03.xsd");
                    reader.ValidationType = ValidationType.Schema;
                    reader.Schemas.Add(myschema);
                    while (reader.Read())
                    {

                    }
                }
                catch (XmlException x)
                {
                    File.Delete(sPathLote);
                    throw new Exception(x.Message);
                }
                catch (XmlSchemaException x)
                {
                    File.Delete(sPathLote);
                    throw new Exception(x.Message);
                }
                #endregion

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        private string MontaXmlCancelamentoV3(TcPedidoCancelamento objPedCanc, X509Certificate2 cert)
        {
            try
            {
                XNamespace pf = "http://www.ginfes.com.br/servico_cancelar_nfse_envio_v03.xsd";
                XNamespace tipos = "http://www.ginfes.com.br/tipos_v03.xsd";
                XNamespace xsi = "http://www.w3.org/2001/XMLSchema-instance";

                XContainer conCancelarNfseEnvio = null;
                conCancelarNfseEnvio = (new XElement(pf + "CancelarNfseEnvio", new XAttribute(xsi + "schemaLocation", "http://www.ginfes.com.br/servico_cancelar_nfse_envio_v03.xsd"),
                                                                              new XAttribute("xmlns", "http://www.ginfes.com.br/servico_cancelar_nfse_envio_v03.xsd"),
                                                                              new XAttribute(XNamespace.Xmlns + "tipos", "http://www.ginfes.com.br/tipos_v03.xsd"),
                                                                              new XAttribute(XNamespace.Xmlns + "xsi", "http://www.w3.org/2001/XMLSchema-instance"),
                                            new XElement(pf + "Pedido",
                                                new XElement(tipos + "InfPedidoCancelamento",
                                                     new XElement(tipos + "IdentificacaoNfse",
                                                         new XElement(tipos + "Numero", objPedCanc.InfPedidoCancelamento.IdentificacaoNfse.Numero),
                                                         new XElement(tipos + "Cnpj", objPedCanc.InfPedidoCancelamento.IdentificacaoNfse.Cnpj),
                                                         new XElement(tipos + "InscricaoMunicipal", objPedCanc.InfPedidoCancelamento.IdentificacaoNfse.InscricaoMunicipal),
                                                         new XElement(tipos + "CodigoMunicipio", objPedCanc.InfPedidoCancelamento.IdentificacaoNfse.CodigoMunicipio)),
                                                     new XElement(tipos + "CodigoCancelamento", objPedCanc.InfPedidoCancelamento.CodigoCancelamento)))));

                //Valida

                AssinaNFeXml Assinatura = new AssinaNFeXml();
                string sArquivo = Assinatura.ConfigurarArquivo(conCancelarNfseEnvio.ToString(), "tipos:InfPedidoCancelamento", cert);

                Globais glob = new Globais();
                DirectoryInfo dPastaData = new DirectoryInfo(belStaticPastas.PROTOCOLOS + "\\Servicos");
                if (!dPastaData.Exists) { dPastaData.Create(); }
                XmlDocument xdocCanc = new XmlDocument();
                xdocCanc.LoadXml(sArquivo);
                xdocCanc.Save(belStaticPastas.PROTOCOLOS + "\\Servicos\\ped_canc_" + objPedCanc.InfPedidoCancelamento.IdentificacaoNfse.Numero + ".xml");

                Globais getschema = new Globais();

                XmlSchemaCollection myschema = new XmlSchemaCollection();
                XmlValidatingReader reader;
                XmlParserContext context = new XmlParserContext(null, null, "", XmlSpace.None);

                reader = new XmlValidatingReader(sArquivo, XmlNodeType.Element, context);

                myschema.Add("http://www.ginfes.com.br/servico_cancelar_nfse_envio_v03.xsd", belStaticPastas.SCHEMA_NFSE + "\\servico_cancelar_nfse_envio_v03.xsd");

                reader.ValidationType = ValidationType.Schema;

                reader.Schemas.Add(myschema);

                while (reader.Read())
                {
                }


                return "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + sArquivo;
            }
            catch (Exception ex)
            {
                return "";
                throw;
            }
        }
        private string MontaXmlCancelamentoHomo(TcPedidoCancelamento objPedCanc, X509Certificate2 cert)
        {
            try
            {
                XNamespace pf = "http://www.ginfes.com.br/servico_cancelar_nfse_envio";
                //XNamespace tipos = "http://www.ginfes.com.br/tipos";
                XContainer conCancelarNfseEnvio = null;
                conCancelarNfseEnvio = (new XElement(pf + "CancelarNfseEnvio", new XAttribute("xmlns", "http://www.ginfes.com.br/servico_cancelar_nfse_envio"),
                                           // new XAttribute(XNamespace.Xmlns + "tipos", "http://www.ginfes.com.br/tipos"),
                                        new XElement(pf + "Prestador", new XElement(pf + "Cnpj", objPedCanc.InfPedidoCancelamento.IdentificacaoNfse.Cnpj),
                                                                      ((objPedCanc.InfPedidoCancelamento.IdentificacaoNfse.InscricaoMunicipal != "") ? new XElement(pf + "InscricaoMunicipal", objPedCanc.InfPedidoCancelamento.IdentificacaoNfse.InscricaoMunicipal) : null)),
                                        new XElement(pf + "NumeroNfse", objPedCanc.InfPedidoCancelamento.IdentificacaoNfse.Numero)));

                //Valida

                AssinaNFeXml Assinatura = new AssinaNFeXml();
                string sArquivo = Assinatura.ConfigurarArquivo(conCancelarNfseEnvio.ToString(), "NumeroNfse", cert);

                Globais glob = new Globais();
                DirectoryInfo dPastaData = new DirectoryInfo(belStaticPastas.PROTOCOLOS + "\\Servicos");
                if (!dPastaData.Exists) { dPastaData.Create(); }
                XmlDocument xdocCanc = new XmlDocument();
                xdocCanc.LoadXml(sArquivo);
                xdocCanc.Save(belStaticPastas.PROTOCOLOS + "\\Servicos\\ped_canc_" + objPedCanc.InfPedidoCancelamento.IdentificacaoNfse.Numero + ".xml");

                Globais getschema = new Globais();

                XmlSchemaCollection myschema = new XmlSchemaCollection();
                XmlValidatingReader reader;
                XmlParserContext context = new XmlParserContext(null, null, "", XmlSpace.None);

                sArquivo = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + sArquivo;
                //reader = new XmlValidatingReader(sArquivo, XmlNodeType.Element, context);

                //myschema.Add("http://www.ginfes.com.br/servico_cancelar_nfse_envio", getschema.LeRegConfig("PastaSchema") + "\\servico_cancelar_nfse_envio_v02.xsd");

                //reader.ValidationType = ValidationType.Schema;

                //reader.Schemas.Add(myschema);

                //while (reader.Read())
                //{ }


                return sArquivo;
            }
            catch (Exception ex)
            {
                return "";
                throw;
            }
        }
Esempio n. 5
0
        private string MontaXmlConsultaLote(tcIdentificacaoPrestador objPrestador)
        {
            XmlSchemaCollection myschema = new XmlSchemaCollection();
            XmlValidatingReader reader;
            try
            {
                XNamespace tipos = "http://www.ginfes.com.br/tipos_v03.xsd";
                XNamespace pf = "http://www.ginfes.com.br/servico_consultar_lote_rps_envio_v03.xsd";
                XContainer conPrestador = null;
                XContainer conProtocolo = null;

                XContainer conConsultarLoteRpsEnvio = (new XElement(pf + "ConsultarLoteRpsEnvio", new XAttribute("xmlns", "http://www.ginfes.com.br/servico_consultar_lote_rps_envio_v03.xsd"),
                                                                        new XAttribute(XNamespace.Xmlns + "tipos", "http://www.ginfes.com.br/tipos_v03.xsd")));

                conPrestador = (new XElement(pf + "Prestador",
                    new XElement(tipos + "Cnpj", objPrestador.Cnpj),
                                                                     ((objPrestador.InscricaoMunicipal != "") ? new XElement(tipos + "InscricaoMunicipal", objPrestador.InscricaoMunicipal) : null)));

                conProtocolo = new XElement(pf + "Protocolo", Protocolo);


                conConsultarLoteRpsEnvio.Add(conPrestador);
                conConsultarLoteRpsEnvio.Add(conProtocolo);
                AssinaNFeXml Assinatura = new AssinaNFeXml();
                string sArquivo = Assinatura.ConfigurarArquivo(conConsultarLoteRpsEnvio.ToString(), "Protocolo", cert);

                //Valida
                Globais getschema = new Globais();

                XmlParserContext context = new XmlParserContext(null, null, "", XmlSpace.None);

                reader = new XmlValidatingReader(sArquivo, XmlNodeType.Element, context);

                myschema.Add("http://www.ginfes.com.br/servico_consultar_lote_rps_envio_v03.xsd", belStaticPastas.SCHEMA_NFSE + "\\servico_consultar_lote_rps_envio_v03.xsd");

                reader.ValidationType = ValidationType.Schema;

                reader.Schemas.Add(myschema);

                while (reader.Read())
                { }




                return sArquivo;

            }
            catch (Exception ex)
            {

                throw;
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Gera a Estrutura do XML da NF-e
        /// </summary>
        /// <param name="sNF"></param>
        /// <param name="cert"></param>
        /// <param name="sEmp"></param>
        /// <param name="sNomeArq"></param>
        /// <param name="iStatusAtualSistema"</param>
        public void geraArquivoNFE(List<string> sNF, X509Certificate2 cert, string sEmp, string sNomeArq)
        {
            string sPath = "";
            sPath = (sFormaEmiNFe.Equals("2") ? belStaticPastas.CONTINGENCIA + @sNomeArq : belStaticPastas.ENVIO + @sNomeArq);
            Globais glob = new Globais();
            int iCount = 0;

            if (File.Exists(sPath))
            {
                File.Delete(sPath);
            }
            string sCasasVlUnit = glob.LeRegConfig("QtdeCasasVlUnit");
            sCasasVlUnit = (sCasasVlUnit == "" ? "000000" : ("").PadLeft(Convert.ToInt32(sCasasVlUnit), '0'));

            foreach (var i in lTotNota)
            {
                string sUF;
                string sNota = sNF[iCount];
                string sNFe = "NFe" + GeraChave(sEmp, sNota);
                XDocument xdoc = new XDocument();

                #region XML_Principal
                XNamespace pf = "http://www.portalfiscal.inf.br/nfe";
                //XContainer conenv = new XElement(pf + "enviNFe", new XAttribute("xmlns", "http://www.portalfiscal.inf.br/nfe"),
                //                                           new XAttribute("versao", "2.00"),
                //                                           new XElement(pf + "idLote", sNomeArq.Substring(7, 15)));
                #endregion

                #region XML_Cabeçalho
                //new XAttribute(XNamespace.Xmlns + "xsi", "http://www.w3.org/2001/XMLSchema-instance"),

                XContainer concabec = (new XElement(pf + "NFe", new XAttribute("xmlns", "http://www.portalfiscal.inf.br/nfe")));
                XContainer coninfnfe = (new XElement(pf + "infNFe", new XAttribute("Id", sNFe),
                                                                    new XAttribute("versao", "2.00")));


                #endregion

                #region Ide
                XContainer conide;
                try
                {
                    belIde objide = i[0] as belIde;
                    #region XML_ide
                    conide = (new XElement(pf + "ide", new XElement(pf + "cUF", objide.Cuf.ToString()),
                                                                new XElement(pf + "cNF", objide.Cnf.ToString()),
                                                                new XElement(pf + "natOp", objide.Natop.ToString()),
                                                                new XElement(pf + "indPag", objide.Indpag.ToString()),
                                                                new XElement(pf + "mod", objide.Mod.ToString()),
                                                                new XElement(pf + "serie", objide.Serie.ToString()),
                                                                new XElement(pf + "nNF", objide.Nnf.ToString()),
                                                                new XElement(pf + "dEmi", objide.Demi.ToString("yyyy-MM-dd")),
                                                                new XElement(pf + "dSaiEnt", objide.Dsaient.ToString("yyyy-MM-dd")),
                                                                new XElement(pf + "hSaiEnt", objide.HSaiEnt.ToString("HH:mm:ss")), // NFe_2.0
                                                                new XElement(pf + "tpNF", objide.Tpnf.ToString()),
                                                                new XElement(pf + "cMunFG", objide.Cmunfg.ToString()),
                                                                (objide.belNFref != null ?
                                                                (from c in objide.belNFref
                                                                 select new XElement(pf + "NFref",
                                                                            (c.RefNFe != null ? new XElement(pf + "refNFe", c.RefNFe) : null),
                                                                           (c.cUF != null ? (new XElement(pf + "refNF",
                                                                            (c.cUF != null ? new XElement(pf + "cUF", c.cUF) : null),
                                                                             (c.AAMM != null ? new XElement(pf + "AAMM", c.AAMM) : null),
                                                                             (c.CNPJ != null ? new XElement(pf + "CNPJ", c.CNPJ) : null),
                                                                             (c.mod != null ? new XElement(pf + "mod", c.mod) : null),
                                                                             (c.serie != null ? new XElement(pf + "serie", c.serie) : null),
                                                                             (c.nNF != null ? new XElement(pf + "nNF", c.nNF) : null))) : null))) : null),//NFe_2.0_Verificar ID B14 - B20a - B20i - 
                                                                new XElement(pf + "tpImp", objide.Tpimp.ToString()),
                                                                new XElement(pf + "tpEmis", objide.Tpemis.ToString()),
                                                                new XElement(pf + "cDV", objide.Cdv.ToString()),
                                                                new XElement(pf + "tpAmb", objide.Tpamb.ToString()),
                                                                new XElement(pf + "finNFe", objide.Finnfe.ToString()),
                                                                new XElement(pf + "procEmi", objide.Procemi.ToString()),
                                                                new XElement(pf + "verProc", objide.Verproc.ToString()),

                                                                ((objide.Tpemis.Equals("2")) || (objide.Tpemis.Equals("3")) ?
                                                                                      new XElement(pf + "dhCont", HLP.Util.Util.GetDateServidor().ToString("yyyy-MM-ddTHH:mm:ss")) : null), // NFe_2.0
                                                                ((objide.Tpemis.Equals("2")) || (objide.Tpemis.Equals("3")) ?
                                                                                      new XElement(pf + "xJust", (iStatusAtualSistema == 2 ? "FALHA DE CONEXÃO COM INTERNET" : "FALHA COM WEB SERVICE DO ESTADO")) : null)));// NFe_2.0
                    #endregion
                }
                catch (Exception x)
                {
                    throw new Exception("Nota de Sequência - " + sNota + "Erro na geração do XML, Regiao XML_ide - " + x.Message);
                }
                #endregion

                #region Emit

                XContainer conemit;
                try
                {
                    belEmit objemit = i[1] as belEmit;
                    #region XML_Emit

                    conemit = (new XElement(pf + "emit", (new XElement(pf + "CNPJ", objemit.Cnpj.ToString())),
                                              new XElement(pf + "xNome", objemit.Xnome.ToString()),
                                              new XElement(pf + "xFant", objemit.Xfant.ToString()),
                                                      new XElement(pf + "enderEmit",
                                                              new XElement(pf + "xLgr", objemit.Xlgr.ToString()),
                                                              new XElement(pf + "nro", objemit.Nro.ToString()),
                                                              (objemit.Xcpl != null ? new XElement(pf + "xCpl", objemit.Xcpl.ToString()) : null),
                                                              new XElement(pf + "xBairro", objemit.Xbairro.ToString()),
                                                              new XElement(pf + "cMun", objemit.Cmun.ToString()),
                                                              new XElement(pf + "xMun", objemit.Xmun.ToString()),
                                                              new XElement(pf + "UF", objemit.Uf.ToString()),
                                                              new XElement(pf + "CEP", objemit.Cep.ToString()),
                                                              new XElement(pf + "cPais", objemit.Cpais.ToString()),
                                                              new XElement(pf + "xPais", objemit.Xpais.ToString()),
                                                              (objemit.Fone != null ? new XElement(pf + "fone", objemit.Fone.ToString()) : null)),
                                              (objemit.Ie != null ? new XElement(pf + "IE", objemit.Ie.ToString()) : null),
                                              (objemit.Iest != null ? new XElement(pf + "IEST", objemit.Iest.ToString()) : null),
                                              (objemit.Im != null ? new XElement(pf + "IM", objemit.Im.ToString()) : null),
                                              (objemit.Cnae != null ? new XElement(pf + "CNAE", objemit.Cnae.ToString()) : null),
                                              new XElement(pf + "CRT", objemit.CRT.ToString()))); // NFe_2.0

                    #endregion
                }
                catch (Exception x)
                {
                    throw new Exception("Nota de Sequência - " + sNota + "Erro na geração do XML, Regiao XML_Emit - " + x.Message);
                }
                #endregion

                #region Dest
                XContainer condest;
                try
                {

                    belDest objdest = i[2] as belDest;
                    sUF = objdest.Uf.ToString();
                    #region XML_Dest
                    objdest.Ie = (objdest.Ie == null ? "" : objdest.Ie);


                    condest = (new XElement(pf + "dest",
                                              (objdest.Cnpj == "EXTERIOR" ? new XElement(pf + "CNPJ") :
                                                 (objdest.Cnpj != null ? new XElement(pf + "CNPJ", objdest.Cnpj) :
                                                                        new XElement(pf + "CPF", objdest.Cpf))),
                                              new XElement(pf + "xNome", (belStatic.TpAmb == 2 ? "NF-E EMITIDA EM AMBIENTE DE HOMOLOGACAO - SEM VALOR FISCAL" : objdest.Xnome.ToString().Trim())),
                                              new XElement(pf + "enderDest",
                                                  new XElement(pf + "xLgr", objdest.Xlgr.ToString()),
                                                  new XElement(pf + "nro", (objdest.Nro != null ? objdest.Nro.ToString() : "0")),
                                                  (objdest.Xcpl != "" ? new XElement(pf + "xCpl", objdest.Xcpl.ToString()) : null),
                                                  new XElement(pf + "xBairro", objdest.Xbairro.ToString()),
                                                  new XElement(pf + "cMun", objdest.Cmun.ToString()),
                                                  new XElement(pf + "xMun", objdest.Xmun.ToString()),
                                                  new XElement(pf + "UF", objdest.Uf.ToString()),
                                                  (objdest.Cep != null ? new XElement(pf + "CEP", objdest.Cep.ToString()) : null),
                                                  new XElement(pf + "cPais", objdest.Cpais.ToString()),
                                                  (objdest.Xpais != null ? new XElement(pf + "xPais", objdest.Xpais.ToString()) : null),
                                                 (objdest.Fone != null ? new XElement(pf + "fone", objdest.Fone.ToString()) : null)),
                                              ((objdest.Ie != null) ? (objdest.Ie != "EXTERIOR" ? new XElement(pf + "IE", objdest.Ie.ToString().Trim()) : new XElement(pf + "IE")) : null), //Claudinei - o.s. sem - 11/02/2010
                                              (objdest.Isuf != null ? new XElement(pf + "ISUF", objdest.Isuf.ToString()) : null)));


                    #endregion
                }
                catch (Exception x)
                {
                    throw new Exception("Nota de Sequência - " + sNota + "Erro na geração do XML, Regiao XML_Dest - " + x.Message);
                }

                #endregion

                #region Det
                List<XElement> lcondet = new List<XElement>();
                try
                {
                    List<belDet> objdet = new List<belDet>();
                    objdet = i[4] as List<belDet>;
                    #region XML_Detalhes

                    foreach (var det in objdet)
                    {
                        XElement condet = (new XElement(pf + "det", new XAttribute("nItem", det.Nitem),
                                           new XElement(pf + "prod",
                                               (det.belProd.Cprod != null ? new XElement(pf + "cProd", det.belProd.Cprod.ToString()) : null),
                                               (det.belProd.Cean != null ? new XElement(pf + "cEAN", det.belProd.Cean.ToString()) : null),
                                               (det.belProd.Xprod != null ? new XElement(pf + "xProd", det.belProd.Xprod.ToString()) : null),
                                               (det.belProd.Ncm != null ? new XElement(pf + "NCM", det.belProd.Ncm.ToString()) : new XElement(pf + "NCM", det.belProd.Ncm = "00000000")), //Claudinei - o.s. 24200 - 01/03/2010
                                               (det.belProd.Extipi != null ? new XElement(pf + "EXTIPI", det.belProd.Extipi.ToString()) : null),
                                               (det.belProd.Genero != null ? new XElement(pf + "genero", det.belProd.Genero.ToString()) : null),
                                               (det.belProd.Cfop != null ? new XElement(pf + "CFOP", det.belProd.Cfop.ToString()) : null),
                                               (det.belProd.Ucom != null ? new XElement(pf + "uCom", det.belProd.Ucom.ToString()) : null),
                                               (det.belProd.Qcom != null ? new XElement(pf + "qCom", det.belProd.Qcom.ToString("#0.0000").Replace(",", ".")) : null),
                                               (det.belProd.Vuncom != null ? new XElement(pf + "vUnCom", det.belProd.Vuncom.ToString("#0." + sCasasVlUnit).Replace(",", ".")) : null),
                                               (det.belProd.Vprod != null ? new XElement(pf + "vProd", det.belProd.Vprod.ToString("#0.00").Replace(",", ".")) : null),
                                               (det.belProd.Ceantrib != null ? new XElement(pf + "cEANTrib", det.belProd.Ceantrib.ToString()) : null),
                                               (det.belProd.Utrib != null ? new XElement(pf + "uTrib", det.belProd.Utrib.ToString()) : null),
                                               (det.belProd.Qtrib != null ? new XElement(pf + "qTrib", det.belProd.Qtrib.ToString("#0.0000").Replace(",", ".")) : null),
                                               (det.belProd.Vuntrib != null ? new XElement(pf + "vUnTrib", det.belProd.Vuntrib.ToString("#0." + sCasasVlUnit).Replace(",", ".")) : null),
                                               ((det.belProd.Vfrete != null) && (det.belProd.Vfrete != 0) ? new XElement(pf + "vFrete", det.belProd.Vfrete.ToString("#0.00").Replace(",", ".")) : null),
                                               ((det.belProd.Vseg != null) && (det.belProd.Vseg != 0) ? new XElement(pf + "vSeg", det.belProd.Vseg.ToString("#0.00").Replace(",", ".")) : null),
                                               (((det.belProd.Vdesc != null) && (det.belProd.Vdesc != 0)) ? new XElement(pf + "vDesc", det.belProd.Vdesc.ToString("#0.00").Replace(",", ".")) : null),
                                               ((det.belProd.VOutro != null) && (det.belProd.VOutro != 0) ? new XElement(pf + "vOutro", det.belProd.VOutro.ToString("#0.00").Replace(",", ".")) : null), //NFe_2.0 
                                               (det.belProd.IndTot != null ? new XElement(pf + "indTot", det.belProd.IndTot.ToString()) : null), //NFe_2.0
                                               ((det.belProd.belDI != null) ? from DI in det.belProd.belDI
                                                                              where DI.nDI != null
                                                                                    && DI.xLocDesemb != null
                                                                                    && DI.UFDesemb != null
                                                                                    && DI.cExportador != null
                                                                              select new XElement(pf + "DI",
                                                                                 (DI.nDI != "" ? new XElement(pf + "nDI", DI.nDI) : null),
                                                                                  new XElement(pf + "dDI", DI.DDI.ToString("yyyy-MM-dd")),
                                                                                 (DI.xLocDesemb != "" ? new XElement(pf + "xLocDesemb", DI.xLocDesemb) : null),
                                                                                 (DI.UFDesemb != "" ? new XElement(pf + "UFDesemb", DI.UFDesemb) : null),
                                                                                  new XElement(pf + "dDesemb", DI.dDesemb.ToString("yyyy-MM-dd")),
                                                                                 (DI.cExportador != "" ? new XElement(pf + "cExportador", DI.cExportador) : null),
                                                                                  from adic in DI.adi
                                                                                  where adic.cFabricante != null
                                                                                  select new XElement(pf + "adi",
                                                                                      new XElement(pf + "nAdicao", adic.nAdicao),
                                                                                      new XElement(pf + "nSeqAdic", adic.nSeqAdic),
                                                                                     (adic.cFabricante != "" ? new XElement(pf + "cFabricante", adic.cFabricante) : null),
                                                                                      new XElement(pf + "vDescDI", adic.vDescDI))) : null),
                                             ((det.belProd.XPed != "") ? new XElement(pf + "xPed", det.belProd.XPed) : null),
                                             ((det.belProd.NItemPed != "") ? new XElement(pf + "nItemPed", det.belProd.NItemPed) : null)),
                                                                                      new XElement(pf + "imposto",

                                               //---------------ICMS-----------------//

                                               new XElement(pf + "ICMS",

                                                   //-------------ICMS00-------------//

                                                   (det.belImposto.belIcms.belIcms00 != null ?
                                                   new XElement(pf + "ICMS00",
                                                        (det.belImposto.belIcms.belIcms00.Orig != null ? new XElement(pf + "orig", det.belImposto.belIcms.belIcms00.Orig.ToString()) : null),
                                                        (det.belImposto.belIcms.belIcms00.Cst != null ? new XElement(pf + "CST", det.belImposto.belIcms.belIcms00.Cst.ToString()) : null),
                                                        (det.belImposto.belIcms.belIcms00.Modbc != null ? new XElement(pf + "modBC", det.belImposto.belIcms.belIcms00.Modbc.ToString()) : null),
                                                        (det.belImposto.belIcms.belIcms00.Vbc != null ? new XElement(pf + "vBC", det.belImposto.belIcms.belIcms00.Vbc.ToString("#0.00").Replace(",", ".")) : null),
                                                        (det.belImposto.belIcms.belIcms00.Picms != null ? new XElement(pf + "pICMS", det.belImposto.belIcms.belIcms00.Picms.ToString("#0.00").Replace(",", ".")) : null),
                                                        (det.belImposto.belIcms.belIcms00.Vicms != null ? new XElement(pf + "vICMS", det.belImposto.belIcms.belIcms00.Vicms.ToString("#0.00").Replace(",", ".")) : null)) : null),

                                                    //-------------ICMS10-------------//

                                                    (det.belImposto.belIcms.belIcms10 != null ?
                                                    new XElement(pf + "ICMS10",
                                                        (det.belImposto.belIcms.belIcms10.Orig != null ? new XElement(pf + "orig", det.belImposto.belIcms.belIcms10.Orig.ToString()) : null),
                                                        (det.belImposto.belIcms.belIcms10.Cst != null ? new XElement(pf + "CST", det.belImposto.belIcms.belIcms10.Cst.ToString()) : null),
                                                        (det.belImposto.belIcms.belIcms10.Modbc != null ? new XElement(pf + "modBC", det.belImposto.belIcms.belIcms10.Modbc.ToString()) : null),
                                                        (det.belImposto.belIcms.belIcms10.Vbc != null ? new XElement(pf + "vBC", det.belImposto.belIcms.belIcms10.Vbc.ToString("#0.00").Replace(",", ".")) : null),
                                                        (det.belImposto.belIcms.belIcms10.Picms != null ? new XElement(pf + "pICMS", det.belImposto.belIcms.belIcms10.Picms.ToString("#0.00").Replace(",", ".")) : null),
                                                        (det.belImposto.belIcms.belIcms10.Vicms != null ? new XElement(pf + "vICMS", det.belImposto.belIcms.belIcms10.Vicms.ToString("#0.00").Replace(",", ".")) : null),
                                                        (det.belImposto.belIcms.belIcms10.Modbcst != null ? new XElement(pf + "modBCST", det.belImposto.belIcms.belIcms10.Modbcst.ToString()) : null),
                                                        (det.belImposto.belIcms.belIcms10.Pmvast != 0 ? new XElement(pf + "pMVAST", det.belImposto.belIcms.belIcms10.Pmvast.ToString("#0.00").Replace(",", ".")) : null), //Claudinei - o.s. sem - 11/03/2010
                                                        (det.belImposto.belIcms.belIcms10.Predbcst.ToString() != "0" ? new XElement(pf + "pRedBCST", det.belImposto.belIcms.belIcms10.Predbcst.ToString("#0.00").Replace(",", ".")) : null),
                                                        (det.belImposto.belIcms.belIcms10.Vbcst != null ? new XElement(pf + "vBCST", det.belImposto.belIcms.belIcms10.Vbcst.ToString("#0.00").Replace(",", ".")) : null),
                                                        (det.belImposto.belIcms.belIcms10.Picmsst != null ? new XElement(pf + "pICMSST", det.belImposto.belIcms.belIcms10.Picmsst.ToString("#0.00").Replace(",", ".")) : null),
                                                        (det.belImposto.belIcms.belIcms10.Vicmsst != null ? new XElement(pf + "vICMSST", det.belImposto.belIcms.belIcms10.Vicmsst.ToString("#0.00").Replace(",", ".")) : null)) : null),

                                                    //-------------ICMS20-------------//

                                                    (det.belImposto.belIcms.belIcms20 != null ?
                                                    new XElement(pf + "ICMS20",
                                                        (det.belImposto.belIcms.belIcms20.Orig != null ? new XElement(pf + "orig", det.belImposto.belIcms.belIcms20.Orig.ToString()) : null),
                                                        (det.belImposto.belIcms.belIcms20.Cst != null ? new XElement(pf + "CST", det.belImposto.belIcms.belIcms20.Cst.ToString()) : null),
                                                        (det.belImposto.belIcms.belIcms20.Modbc != null ? new XElement(pf + "modBC", det.belImposto.belIcms.belIcms20.Modbc.ToString()) : null),
                                                        (det.belImposto.belIcms.belIcms20.Predbc != null ? new XElement(pf + "pRedBC", det.belImposto.belIcms.belIcms20.Predbc.ToString("#0.00").Replace(",", ".")) : null),
                                                        (det.belImposto.belIcms.belIcms20.Vbc != null ? new XElement(pf + "vBC", det.belImposto.belIcms.belIcms20.Vbc.ToString("#0.00").Replace(",", ".")) : null),
                                                        (det.belImposto.belIcms.belIcms20.Picms != null ? new XElement(pf + "pICMS", det.belImposto.belIcms.belIcms20.Picms.ToString("#0.00").Replace(",", ".")) : null),
                                                        (det.belImposto.belIcms.belIcms20.Vicms != null ? new XElement(pf + "vICMS", det.belImposto.belIcms.belIcms20.Vicms.ToString("#0.00").Replace(",", ".")) : null)) : null),

                                                    //-------------ICMS30-------------//

                                                    (det.belImposto.belIcms.belIcms30 != null ?
                                                    new XElement(pf + "ICMS30",
                                                        (det.belImposto.belIcms.belIcms30.Orig != null ? new XElement(pf + "orig", det.belImposto.belIcms.belIcms30.Orig.ToString()) : null),
                                                        (det.belImposto.belIcms.belIcms30.Cst != null ? new XElement(pf + "CST", det.belImposto.belIcms.belIcms30.Cst.ToString()) : null),
                                                        (det.belImposto.belIcms.belIcms30.Modbcst != null ? new XElement(pf + "modBCST", det.belImposto.belIcms.belIcms30.Modbcst.ToString()) : null),
                                                        (det.belImposto.belIcms.belIcms30.Pmvast != 0 ? new XElement(pf + "pMVAST", det.belImposto.belIcms.belIcms30.Pmvast.ToString("#0.00").Replace(",", ".")) : null), //Claudinei - o.s. sem - 12/03/2010
                                                        (det.belImposto.belIcms.belIcms30.Predbcst.ToString() != "0" ? new XElement(pf + "pRedBCST", det.belImposto.belIcms.belIcms30.Predbcst.ToString("#0.00").Replace(",", ".")) : null),
                                                        (det.belImposto.belIcms.belIcms30.Vbcst != null ? new XElement(pf + "vBCST", det.belImposto.belIcms.belIcms30.Vbcst.ToString("#0.00").Replace(",", ".")) : null),
                                                        (det.belImposto.belIcms.belIcms30.Picmsst != null ? new XElement(pf + "pICMSST", det.belImposto.belIcms.belIcms30.Picmsst.ToString("#0.00").Replace(",", ".")) : null),
                                                        (det.belImposto.belIcms.belIcms30.Vicmsst != null ? new XElement(pf + "vICMSST", det.belImposto.belIcms.belIcms30.Vicmsst.ToString("#0.00").Replace(",", ".")) : null)) : null),

                                                    //-------------ICMS40-------------//

                                                    (det.belImposto.belIcms.belIcms40 != null ?
                                                    new XElement(pf + "ICMS40",
                                                        (det.belImposto.belIcms.belIcms40.Orig != null ? new XElement(pf + "orig", det.belImposto.belIcms.belIcms40.Orig.ToString()) : null),
                                                        (det.belImposto.belIcms.belIcms40.Cst != null ? new XElement(pf + "CST", det.belImposto.belIcms.belIcms40.Cst.ToString()) : null),
                                                        (det.belImposto.belIcms.belIcms40.Vicms > 0 ? new XElement(pf + "vICMS", det.belImposto.belIcms.belIcms40.Vicms.ToString()) : null), //NFe_2.0
                                                        (det.belImposto.belIcms.belIcms40.Vicms > 0 ? new XElement(pf + "motDesICMS", det.belImposto.belIcms.belIcms40.motDesICMS.ToString()) : null)) : null),//NFe_2.0

                                                    //-------------ICMS41-------------//

                                                    (det.belImposto.belIcms.belIcms41 != null ?
                                                    new XElement(pf + "ICMS41",
                                                        (det.belImposto.belIcms.belIcms41.Orig != null ? new XElement(pf + "orig", det.belImposto.belIcms.belIcms41.Orig.ToString()) : null),
                                                        (det.belImposto.belIcms.belIcms41.Cst != null ? new XElement(pf + "CST", det.belImposto.belIcms.belIcms41.Cst.ToString()) : null),
                                                        (det.belImposto.belIcms.belIcms41.Vicms > 0 ? new XElement(pf + "vICMS", det.belImposto.belIcms.belIcms41.Vicms.ToString()) : null),//NFe_2.0
                                                        (det.belImposto.belIcms.belIcms41.motDesICMS > 0 ? new XElement(pf + "motDesICMS", det.belImposto.belIcms.belIcms41.motDesICMS.ToString()) : null)) : null),//NFe_2.0

                                                    //-------------ICMS50-------------//

                                                    (det.belImposto.belIcms.belIcms50 != null ?
                                                    new XElement(pf + "ICMS50",
                                                        (det.belImposto.belIcms.belIcms50.Orig != null ? new XElement(pf + "orig", det.belImposto.belIcms.belIcms50.Orig.ToString()) : null),
                                                        (det.belImposto.belIcms.belIcms50.Cst != null ? new XElement(pf + "CST", det.belImposto.belIcms.belIcms50.Cst.ToString()) : null),
                                                            (det.belImposto.belIcms.belIcms50.Vicms > 0 ? new XElement(pf + "vICMS", det.belImposto.belIcms.belIcms50.Vicms.ToString()) : null),//NFe_2.0
                                                        (det.belImposto.belIcms.belIcms50.motDesICMS > 0 ? new XElement(pf + "motDesICMS", det.belImposto.belIcms.belIcms50.motDesICMS.ToString()) : null)) : null),//NFe_2.0

                                                    //-------------ICMS51-------------//

                                                    (det.belImposto.belIcms.belIcms51 != null ?
                                                    new XElement(pf + "ICMS51",
                                                        (det.belImposto.belIcms.belIcms51.Orig != null ? new XElement(pf + "orig", det.belImposto.belIcms.belIcms51.Orig.ToString()) : null),
                                                        (det.belImposto.belIcms.belIcms51.Cst != null ? new XElement(pf + "CST", det.belImposto.belIcms.belIcms51.Cst.ToString()) : null),
                                                        (det.belImposto.belIcms.belIcms51.Modbc != null ? new XElement(pf + "modBC", det.belImposto.belIcms.belIcms51.Modbc.ToString()) : null),
                                                        (det.belImposto.belIcms.belIcms51.Predbc != null ? new XElement(pf + "pRedBC", det.belImposto.belIcms.belIcms51.Predbc.ToString("#0.00").Replace(",", ".")) : null),
                                                        (det.belImposto.belIcms.belIcms51.Vbc != null ? new XElement(pf + "vBC", det.belImposto.belIcms.belIcms51.Vbc.ToString("#0.00").Replace(",", ".")) : null),
                                                        (det.belImposto.belIcms.belIcms51.Picms != null ? new XElement(pf + "pICMS", det.belImposto.belIcms.belIcms51.Picms.ToString("#0.00").Replace(",", ".")) : null),
                                                        (det.belImposto.belIcms.belIcms51.Vicms != null ? new XElement(pf + "vICMS", det.belImposto.belIcms.belIcms51.Vicms.ToString("#0.00").Replace(",", ".")) : null)) : null),

                                                    //-------------ICMS60-------------//

                                                    (det.belImposto.belIcms.belIcms60 != null ?
                                                    new XElement(pf + "ICMS60",//Danner - o.s. sem - 12/03/2010
                                                        (det.belImposto.belIcms.belIcms60.Orig != null ? new XElement(pf + "orig", det.belImposto.belIcms.belIcms60.Orig.ToString()) : null),
                                                        (det.belImposto.belIcms.belIcms60.Cst != null ? new XElement(pf + "CST", det.belImposto.belIcms.belIcms60.Cst.ToString()) : null),
                                                        (det.belImposto.belIcms.belIcms60.Vbcst != null ? new XElement(pf + "vBCSTRet", det.belImposto.belIcms.belIcms60.Vbcst.ToString("#0.00").Replace(",", ".")) : null),//NFe_2.0 - Mudança de nome de Tag
                                                        (det.belImposto.belIcms.belIcms60.Vicmsst != null ? new XElement(pf + "vICMSSTRet", det.belImposto.belIcms.belIcms60.Vicmsst.ToString("#0.00").Replace(",", ".")) : null)) : null),//NFe_2.0 Mudança de nome de Tag

                                                    //-------------ICMS70-------------//

                                                    (det.belImposto.belIcms.belIcms70 != null ?
                                                    new XElement(pf + "ICMS70",
                                                        (det.belImposto.belIcms.belIcms70.Orig != null ? new XElement(pf + "orig", det.belImposto.belIcms.belIcms70.Orig.ToString()) : null),
                                                        (det.belImposto.belIcms.belIcms70.Cst != null ? new XElement(pf + "CST", det.belImposto.belIcms.belIcms70.Cst.ToString()) : null),
                                                        (det.belImposto.belIcms.belIcms70.Modbc != null ? new XElement(pf + "modBC", det.belImposto.belIcms.belIcms70.Modbc.ToString()) : null),
                                                        (det.belImposto.belIcms.belIcms70.Predbc != null ? new XElement(pf + "pRedBC", det.belImposto.belIcms.belIcms70.Predbc.ToString("#0.00").Replace(',', '.')) : null), //Danner - o.s. 24091 - 06/02/2010
                                                        (det.belImposto.belIcms.belIcms70.Vbc != null ? new XElement(pf + "vBC", det.belImposto.belIcms.belIcms70.Vbc.ToString("#0.00").Replace(",", ".")) : null),
                                                        (det.belImposto.belIcms.belIcms70.Picms != null ? new XElement(pf + "pICMS", det.belImposto.belIcms.belIcms70.Picms.ToString("#0.00").Replace(",", ".")) : null),
                                                        (det.belImposto.belIcms.belIcms70.Vicms != null ? new XElement(pf + "vICMS", det.belImposto.belIcms.belIcms70.Vicms.ToString("#0.00").Replace(",", ".")) : null),
                                                        (det.belImposto.belIcms.belIcms70.Modbcst != null ? new XElement(pf + "modBCST", det.belImposto.belIcms.belIcms70.Modbcst.ToString()) : null),
                                                        (det.belImposto.belIcms.belIcms70.Pmvast != 0 ? new XElement(pf + "pMVAST", det.belImposto.belIcms.belIcms70.Pmvast.ToString("#0.00").Replace(",", ".")) : null), //Claudinei - o.s. sem - 12/03/2010
                                                        (det.belImposto.belIcms.belIcms70.Predbcst.ToString() != "0" ? new XElement(pf + "pRedBCST", det.belImposto.belIcms.belIcms70.Predbcst.ToString("#0.00").Replace(",", ".")) : null),
                                                        (det.belImposto.belIcms.belIcms70.Vbcst != null ? new XElement(pf + "vBCST", det.belImposto.belIcms.belIcms70.Vbcst.ToString("#0.00").Replace(",", ".")) : null),
                                                        (det.belImposto.belIcms.belIcms70.Picmsst != null ? new XElement(pf + "pICMSST", det.belImposto.belIcms.belIcms70.Picmsst.ToString("#0.00").Replace(",", ".")) : null),
                                                        (det.belImposto.belIcms.belIcms70.Vicmsst != null ? new XElement(pf + "vICMSST", det.belImposto.belIcms.belIcms70.Vicmsst.ToString("#0.00").Replace(",", ".")) : null)) : null),

                                                    //-------------ICMS90-------------//

                                                    (det.belImposto.belIcms.belIcms90 != null ?
                                                    new XElement(pf + "ICMS90",
                                                        (det.belImposto.belIcms.belIcms90.Orig != null ? new XElement(pf + "orig", det.belImposto.belIcms.belIcms90.Orig.ToString()) : null),
                                                        (det.belImposto.belIcms.belIcms90.Cst != null ? new XElement(pf + "CST", det.belImposto.belIcms.belIcms90.Cst.ToString()) : null),
                                                        (det.belImposto.belIcms.belIcms90.Modbc != null ? new XElement(pf + "modBC", det.belImposto.belIcms.belIcms90.Modbc.ToString()) : null),
                                                        (det.belImposto.belIcms.belIcms90.Vbc != null ? new XElement(pf + "vBC", det.belImposto.belIcms.belIcms90.Vbc.ToString("#0.00").Replace(",", ".")) : null),
                                                        (det.belImposto.belIcms.belIcms90.Predbc != 0 ? new XElement(pf + "pRedBC", det.belImposto.belIcms.belIcms90.Predbc.ToString("#0.00").Replace(',', '.')) : null), //Danner - o.s. 24091 - 06/02/2010 //Claudinei - o.s. sem - 24/02/2010
                                                        (det.belImposto.belIcms.belIcms90.Picms != null ? new XElement(pf + "pICMS", det.belImposto.belIcms.belIcms90.Picms.ToString("#0.00").Replace(",", ".")) : null),
                                                        (det.belImposto.belIcms.belIcms90.Vicms != null ? new XElement(pf + "vICMS", det.belImposto.belIcms.belIcms90.Vicms.ToString("#0.00").Replace(",", ".")) : null),
                                                        (det.belImposto.belIcms.belIcms90.Modbcst != null ? new XElement(pf + "modBCST", det.belImposto.belIcms.belIcms90.Modbcst.ToString()) : null),
                                                        (det.belImposto.belIcms.belIcms90.Pmvast != 0 ? new XElement(pf + "pMVAST", det.belImposto.belIcms.belIcms90.Pmvast.ToString("#0.00").Replace(",", ".")) : null), //Claudinei - o.s. 24076 - 01/02/2010
                                                        (det.belImposto.belIcms.belIcms90.Predbcst.ToString() != "0" ? new XElement(pf + "pRedBCST", det.belImposto.belIcms.belIcms90.Predbcst.ToString("#0.00").Replace(",", ".")) : null), //Claudinei - o.s. 24076 - 01/02/2010
                                                        (det.belImposto.belIcms.belIcms90.Vbcst != null ? new XElement(pf + "vBCST", det.belImposto.belIcms.belIcms90.Vbcst.ToString("#0.00").Replace(",", ".")) : null),
                                                        (det.belImposto.belIcms.belIcms90.Picmsst != null ? new XElement(pf + "pICMSST", det.belImposto.belIcms.belIcms90.Picmsst.ToString("#0.00").Replace(",", ".")) : null),
                                                        (det.belImposto.belIcms.belIcms90.Vicmsst != null ? new XElement(pf + "vICMSST", det.belImposto.belIcms.belIcms90.Vicmsst.ToString("#0.00").Replace(",", ".")) : null)) : null),

                                                   //-------------ICMSSN101--------------//
                                                   (det.belImposto.belIcms.belICMSSN101 != null ?
                                                        new XElement(pf + "ICMSSN101",
                                                           (det.belImposto.belIcms.belICMSSN101.orig != null ? new XElement(pf + "orig", det.belImposto.belIcms.belICMSSN101.orig.ToString()) : null),
                                                           new XElement(pf + "CSOSN", det.belImposto.belIcms.belICMSSN101.CSOSN.ToString()),
                                                           (det.belImposto.belIcms.belICMSSN101.pCredSN != null ? new XElement(pf + "pCredSN", det.belImposto.belIcms.belICMSSN101.pCredSN.ToString("#0.00").Replace(",", ".")) : null),
                                                           (det.belImposto.belIcms.belICMSSN101.vCredICMSSN != null ? new XElement(pf + "vCredICMSSN", det.belImposto.belIcms.belICMSSN101.vCredICMSSN.ToString("#0.00").Replace(",", ".")) : null)) : null),

                                                  //-------------ICMSSN102--------------//
                                                   (det.belImposto.belIcms.belICMSSN102 != null ?
                                                        new XElement(pf + "ICMSSN102",
                                                           (det.belImposto.belIcms.belICMSSN102.orig != null ? new XElement(pf + "orig", det.belImposto.belIcms.belICMSSN102.orig.ToString()) : null),
                                                           new XElement(pf + "CSOSN", det.belImposto.belIcms.belICMSSN102.CSOSN.ToString())) : null),

                                                  //-------------ICMSSN201--------------//
                                                   (det.belImposto.belIcms.belICMSSN201 != null ?
                                                        new XElement(pf + (det.belImposto.belIcms.belICMSSN201.CSOSN.Equals("201") ? "ICMSSN201" : "ICMSSN202"),
                                                           (det.belImposto.belIcms.belICMSSN201.orig != null ? new XElement(pf + "orig", det.belImposto.belIcms.belICMSSN201.orig.ToString()) : null),
                                                           new XElement(pf + "CSOSN", det.belImposto.belIcms.belICMSSN201.CSOSN.ToString()),
                                                           (det.belImposto.belIcms.belICMSSN201.modBCST != null ? new XElement(pf + "modBCST", det.belImposto.belIcms.belICMSSN201.modBCST.ToString()) : null),
                                                           (det.belImposto.belIcms.belICMSSN201.pMVAST != 0 ? new XElement(pf + "pMVAST", det.belImposto.belIcms.belICMSSN201.pMVAST.ToString("#0.00").Replace(",", ".")) : null),
                                                           (det.belImposto.belIcms.belICMSSN201.pRedBCST.ToString() != "0" ? new XElement(pf + "pRedBCST", det.belImposto.belIcms.belICMSSN201.pRedBCST.ToString("#0.00").Replace(",", ".")) : null),
                                                           (det.belImposto.belIcms.belICMSSN201.vBCST != null ? new XElement(pf + "vBCST", det.belImposto.belIcms.belICMSSN201.vBCST.ToString("#0.00").Replace(",", ".")) : null),
                                                           (det.belImposto.belIcms.belICMSSN201.pICMSST != null ? new XElement(pf + "pICMSST", det.belImposto.belIcms.belICMSSN201.pICMSST.ToString("#0.00").Replace(",", ".")) : null),
                                                           (det.belImposto.belIcms.belICMSSN201.vICMSST != null ? new XElement(pf + "vICMSST", det.belImposto.belIcms.belICMSSN201.vICMSST.ToString("#0.00").Replace(",", ".")) : null),
                                                           ((det.belImposto.belIcms.belICMSSN201.pCredSN != null && det.belImposto.belIcms.belICMSSN201.CSOSN.Equals("201")) ? new XElement(pf + "pCredSN", det.belImposto.belIcms.belICMSSN201.pCredSN.ToString("#0.00").Replace(",", ".")) : null),
                                                           ((det.belImposto.belIcms.belICMSSN201.vCredICMSSN != null && det.belImposto.belIcms.belICMSSN201.CSOSN.Equals("201")) ? new XElement(pf + "vCredICMSSN", det.belImposto.belIcms.belICMSSN201.vCredICMSSN.ToString("#0.00").Replace(",", ".")) : null)) : null),

                                                  //-------------ICMSSN500--------------//
                                                   (det.belImposto.belIcms.belICMSSN500 != null ?
                                                        new XElement(pf + "ICMSSN500",
                                                           (det.belImposto.belIcms.belICMSSN500.orig != null ? new XElement(pf + "orig", det.belImposto.belIcms.belICMSSN500.orig.ToString()) : null),
                                                           new XElement(pf + "CSOSN", det.belImposto.belIcms.belICMSSN500.CSOSN.ToString()),
                                                           (det.belImposto.belIcms.belICMSSN500.vBCSTRet != null ? new XElement(pf + "vBCSTRet", det.belImposto.belIcms.belICMSSN500.vBCSTRet.ToString("#0.00").Replace(",", ".")) : null),
                                                           (det.belImposto.belIcms.belICMSSN500.vICMSSTRet != null ? new XElement(pf + "vICMSSTRet", det.belImposto.belIcms.belICMSSN500.vICMSSTRet.ToString("#0.00").Replace(",", ".")) : null)) : null),

                                                  //-------------ICMSSN900--------------//
                                                   (det.belImposto.belIcms.belICMSSN900 != null ?
                                                        new XElement(pf + "ICMSSN900",
                                                           (det.belImposto.belIcms.belICMSSN900.orig != null ? new XElement(pf + "orig", det.belImposto.belIcms.belICMSSN900.orig.ToString()) : null),
                                                           new XElement(pf + "CSOSN", det.belImposto.belIcms.belICMSSN900.CSOSN.ToString())) : null)),
                            //(det.belImposto.belIcms.belICMSSN900.modBC != null ? new XElement(pf + "modBC", det.belImposto.belIcms.belICMSSN900.modBC.ToString()) : null),
                            //(det.belImposto.belIcms.belICMSSN900.vBC != null ? new XElement(pf + "vBC", det.belImposto.belIcms.belICMSSN900.vBC.ToString("#0.00").Replace(",", ".")) : null),
                            //(det.belImposto.belIcms.belICMSSN900.pRedBC != null ? new XElement(pf + "pRedBC", det.belImposto.belIcms.belICMSSN900.pRedBC.ToString("#0.00").Replace(",", ".")) : null),
                            //(det.belImposto.belIcms.belICMSSN900.pICMS != null ? new XElement(pf + "pICMS", det.belImposto.belIcms.belICMSSN900.pICMS.ToString("#0.00").Replace(",", ".")) : null),
                            //(det.belImposto.belIcms.belICMSSN900.vICMS != null ? new XElement(pf + "vICMS", det.belImposto.belIcms.belICMSSN900.vICMS.ToString("#0.00").Replace(",", ".")) : null),
                            //(det.belImposto.belIcms.belICMSSN900.modBCST != null ? new XElement(pf + "modBCST", det.belImposto.belIcms.belICMSSN900.modBCST.ToString()) : null),
                            //(det.belImposto.belIcms.belICMSSN900.pMVAST != null ? new XElement(pf + "pMVAST", det.belImposto.belIcms.belICMSSN900.pMVAST.ToString("#0.00").Replace(",", ".")) : null),
                            //(det.belImposto.belIcms.belICMSSN900.pRedBCST != null ? new XElement(pf + "pRedBCST", det.belImposto.belIcms.belICMSSN900.pRedBCST.ToString("#0.00").Replace(",", ".")) : null),
                            //(det.belImposto.belIcms.belICMSSN900.vBCST != null ? new XElement(pf + "vBCST", det.belImposto.belIcms.belICMSSN900.vBCST.ToString("#0.00").Replace(",", ".")) : null),
                            //(det.belImposto.belIcms.belICMSSN900.pICMSST != null ? new XElement(pf + "pICMSST", det.belImposto.belIcms.belICMSSN900.pICMSST.ToString("#0.00").Replace(",", ".")) : null),
                            //(det.belImposto.belIcms.belICMSSN900.vICMSST != null ? new XElement(pf + "vICMSST", det.belImposto.belIcms.belICMSSN900.vICMSST.ToString("#0.00").Replace(",", ".")) : null),
                            //(det.belImposto.belIcms.belICMSSN900.vBCSTRet != null ? new XElement(pf + "vBCSTRet", det.belImposto.belIcms.belICMSSN900.vBCSTRet.ToString("#0.00").Replace(",", ".")) : null),
                            //(det.belImposto.belIcms.belICMSSN900.vICMSSTRet != null ? new XElement(pf + "vICMSSTRet", det.belImposto.belIcms.belICMSSN900.vICMSSTRet.ToString("#0.00").Replace(",", ".")) : null),
                            //(det.belImposto.belIcms.belICMSSN900.pCredSN != null ? new XElement(pf + "pCredSN", det.belImposto.belIcms.belICMSSN900.pCredSN.ToString("#0.00").Replace(",", ".")) : null),
                            //(det.belImposto.belIcms.belICMSSN900.vCredICMSSN != null ? new XElement(pf + "vCredICMSSN", det.belImposto.belIcms.belICMSSN900.vCredICMSSN.ToString("#0.00").Replace(",", ".")) : null)) : null)),

                                    //---------------IPI-------------//
                                        (det.belImposto.belIpi != null ?
                                        new XElement(pf + "IPI",
                                            (det.belImposto.belIpi.Clenq != null ?
                                                new XElement(pf + "clEnq", det.belImposto.belIpi.Clenq.ToString()) : null),
                                            (det.belImposto.belIpi.Cnpjprod != null ?
                                                new XElement(pf + "CNPJProd", det.belImposto.belIpi.Cnpjprod.ToString()) : null),
                                            (det.belImposto.belIpi.Cselo != null ?
                                                new XElement(pf + "cSelo", det.belImposto.belIpi.Cselo.ToString()) : null),
                                            (det.belImposto.belIpi.Qselo != null ?
                                                new XElement(pf + "qSelo", det.belImposto.belIpi.Qselo.ToString()) : null),
                                            (det.belImposto.belIpi.Cenq != null ?
                                                new XElement(pf + "cEnq", det.belImposto.belIpi.Cenq.ToString()) : null),

                                            //-----------IPITrib-----------//    

                                            (det.belImposto.belIpi.belIpitrib != null ?
                                            new XElement(pf + "IPITrib",
                                                (det.belImposto.belIpi.belIpitrib.Cst != null ? new XElement(pf + "CST", det.belImposto.belIpi.belIpitrib.Cst.ToString()) : null),
                                                (det.belImposto.belIpi.belIpitrib.Vbc != null ? new XElement(pf + "vBC", det.belImposto.belIpi.belIpitrib.Vbc.ToString("#0.00").Replace(",", ".")) : null),
                                                (det.belImposto.belIpi.belIpitrib.Qunid != null ? new XElement(pf + "qUnid", det.belImposto.belIpi.belIpitrib.Qunid.ToString()) : null),
                                                (det.belImposto.belIpi.belIpitrib.Vunid != 0 ? new XElement(pf + "vUnid", det.belImposto.belIpi.belIpitrib.Vunid.ToString("#0.0000").Replace(",", ".")) : null),
                                                (det.belImposto.belIpi.belIpitrib.Pipi != null ? new XElement(pf + "pIPI", det.belImposto.belIpi.belIpitrib.Pipi.ToString("#0.00").Replace(",", ".")) : null),
                                                (det.belImposto.belIpi.belIpitrib.Vipi != null ? new XElement(pf + "vIPI", det.belImposto.belIpi.belIpitrib.Vipi.ToString("#0.00").Replace(",", ".")) : null)) : null),

                                            //-----------IPINT-----------//

                                            (det.belImposto.belIpi.belIpint != null ?
                                            new XElement(pf + "IPINT",
                                                (det.belImposto.belIpi.belIpint != null ? new XElement(pf + "CST", det.belImposto.belIpi.belIpint.Cst.ToString()) : null)) : null)) : null),




                                   //--------------II--------------//             
                                   (det.belImposto.belIi != null ?
                                   new XElement(pf + "II",
                                       (det.belImposto.belIi.Vbc != null ? new XElement(pf + "vBC", det.belImposto.belIi.Vbc.ToString("#0.00").Replace(',', '.')) : null),
                                       (det.belImposto.belIi.Vdespadu != null ? new XElement(pf + "vDespAdu", det.belImposto.belIi.Vdespadu.ToString()) : null),
                                       (det.belImposto.belIi.Vii != null ? new XElement(pf + "vII", det.belImposto.belIi.Vii.ToString("0.00").Replace(',', '.')) : null),
                                       (det.belImposto.belIi.Viof != null ? new XElement(pf + "vIOF", det.belImposto.belIi.Viof.ToString("#0.00").Replace(',', '.')) : null)) : null),



                           //----------------PIS------------//

                             (det.belImposto.belPis != null ?
                             new XElement(pf + "PIS",

                                 //-----------PISAliq----------//

                                 (det.belImposto.belPis.belPisaliq != null ?
                                 new XElement(pf + "PISAliq",
                                     (det.belImposto.belPis.belPisaliq.Cst != null ? new XElement(pf + "CST", det.belImposto.belPis.belPisaliq.Cst.ToString()) : null),
                                     (det.belImposto.belPis.belPisaliq.Vbc != null ? new XElement(pf + "vBC", det.belImposto.belPis.belPisaliq.Vbc.ToString("#0.00").Replace(",", ".")) : null),
                                     (det.belImposto.belPis.belPisaliq.Ppis != null ? new XElement(pf + "pPIS", det.belImposto.belPis.belPisaliq.Ppis.ToString("#0.00").Replace(",", ".")) : null),
                                     (det.belImposto.belPis.belPisaliq.Vpis != null ? new XElement(pf + "vPIS", det.belImposto.belPis.belPisaliq.Vpis.ToString("#0.00").Replace(",", ".")) : null)) : null),

                                //-----------PISQtde-----------//                               
                                 (det.belImposto.belPis.belPisqtde != null ?
                                 new XElement(pf + "PISQtde",
                                     (det.belImposto.belPis.belPisqtde.Cst != null ? new XElement(pf + "CST", det.belImposto.belPis.belPisqtde.Cst.ToString()) : null),
                                     (det.belImposto.belPis.belPisqtde.Qbcprod != 0 ? new XElement(pf + "qBCProd", det.belImposto.belPis.belPisqtde.Qbcprod.ToString()) : null),
                                     (det.belImposto.belPis.belPisqtde.Valiqprod != null ? new XElement(pf + "vAliqProd", det.belImposto.belPis.belPisqtde.Valiqprod.ToString("#0.00").Replace(",", ".")) : null),
                                     (det.belImposto.belPis.belPisqtde.Vpis != null ? new XElement(pf + "vPIS", det.belImposto.belPis.belPisqtde.Vpis.ToString("#0.00").Replace(",", ".")) : null)) : null),

                                 //----------PISNT------------//

                                 (det.belImposto.belPis.belPisnt != null ?
                                 new XElement(pf + "PISNT",
                                     (det.belImposto.belPis.belPisnt.Cst != null ? new XElement(pf + "CST", det.belImposto.belPis.belPisnt.Cst.ToString()) : null)) : null),

                                 //----------PISOutr-----------//

                                 (det.belImposto.belPis.belPisoutr != null ?
                                 new XElement(pf + "PISOutr",
                                     (det.belImposto.belPis.belPisoutr.Cst != null ? new XElement(pf + "CST", det.belImposto.belPis.belPisoutr.Cst.ToString()) : null),
                                     (det.belImposto.belPis.belPisoutr.Vbc != null ? new XElement(pf + "vBC", det.belImposto.belPis.belPisoutr.Vbc.ToString("#0.00").Replace(",", ".")) : null),
                                     (det.belImposto.belPis.belPisoutr.Ppis != null ? new XElement(pf + "pPIS", det.belImposto.belPis.belPisoutr.Ppis.ToString("#0.00").Replace(",", ".")) : null),
                                     (det.belImposto.belPis.belPisoutr.Qbcprod != 0 ? new XElement(pf + "qBCProd", det.belImposto.belPis.belPisoutr.Qbcprod.ToString()) : null),
                                     (det.belImposto.belPis.belPisoutr.Valiqprod != 0 ? new XElement(pf + "vAliqProd", det.belImposto.belPis.belPisoutr.Valiqprod.ToString("#0.0000").Replace(",", ".")) : null),
                                     (det.belImposto.belPis.belPisoutr.Vpis != null ? new XElement(pf + "vPIS", det.belImposto.belPis.belPisoutr.Vpis.ToString("#0.00").Replace(",", ".")) : null)) : null)) : null),







                             //---------------COFINS---------------//
                             (det.belImposto.belCofins != null ?
                             new XElement(pf + "COFINS",

                                 //-----------COFINSAliq------------//

                                 (det.belImposto.belCofins.belCofinsaliq != null ?
                                 new XElement(pf + "COFINSAliq",
                                     new XElement(pf + "CST", det.belImposto.belCofins.belCofinsaliq.Cst.ToString()),
                                     new XElement(pf + "vBC", det.belImposto.belCofins.belCofinsaliq.Vbc.ToString("#0.00").Replace(",", ".")),
                                     new XElement(pf + "pCOFINS", det.belImposto.belCofins.belCofinsaliq.Pcofins.ToString("#0.00").Replace(",", ".")),
                                     new XElement(pf + "vCOFINS", det.belImposto.belCofins.belCofinsaliq.Vcofins.ToString("#0.00").Replace(",", "."))) : null),

                                 //------------COFINSQtde------------//

                                 (det.belImposto.belCofins.belCofinsqtde != null ?
                                 new XElement(pf + "COFINSQtde",
                                     new XElement(pf + "CST", det.belImposto.belCofins.belCofinsqtde.Cst.ToString()),
                                     new XElement(pf + "pBCProd", det.belImposto.belCofins.belCofinsqtde.Qbcprod.ToString()),
                                     new XElement(pf + "vAliqProd", det.belImposto.belCofins.belCofinsqtde.Valiqprod.ToString("#0.00").Replace(",", ".")),
                                     new XElement(pf + "vCOFINS", det.belImposto.belCofins.belCofinsqtde.Vcofins.ToString("#0.00").Replace(",", "."))) : null),

                                 //------------COFINSNT--------------//

                                 (det.belImposto.belCofins.belCofinsnt != null ?
                                 new XElement(pf + "COFINSNT",
                                     (det.belImposto.belCofins.belCofinsnt.Cst != null ? new XElement(pf + "CST", det.belImposto.belCofins.belCofinsnt.Cst.ToString()) : null)) : null),

                                 //------------COFINSOutr--------------//

                                 (det.belImposto.belCofins.belCofinsoutr != null ?
                                 new XElement(pf + "COFINSOutr",
                                     new XElement(pf + "CST", det.belImposto.belCofins.belCofinsoutr.Cst.ToString()),
                                     new XElement(pf + "vBC", det.belImposto.belCofins.belCofinsoutr.Vbc.ToString("#0.00").Replace(",", ".")),
                                     new XElement(pf + "pCOFINS", det.belImposto.belCofins.belCofinsoutr.Pcofins.ToString("#0.00").Replace(",", ".")),
                                     new XElement(pf + "vCOFINS", det.belImposto.belCofins.belCofinsoutr.Vcofins.ToString("#0.00").Replace(",", "."))) : null)) : null),


                             //----------------ISSQN-----------------//

                             (det.belImposto.belIss != null ?
                             new XElement(pf + "ISSQN",
                                 (det.belImposto.belIss.Vbc != null ? new XElement(pf + "vBC", det.belImposto.belIss.Vbc.ToString("#0.00").Replace(",", ".")) : null),
                                 (det.belImposto.belIss.Valiq != null ? new XElement(pf + "vAliq", det.belImposto.belIss.Valiq.ToString("#0.00").Replace(",", ".")) : null),
                                 (det.belImposto.belIss.Vissqn != null ? new XElement(pf + "vISSQN", det.belImposto.belIss.Vissqn.ToString("#0.00").Replace(",", ".")) : null),
                                 (det.belImposto.belIss.Cmunfg != null ? new XElement(pf + "cMunFG", det.belImposto.belIss.Cmunfg.ToString()) : null),
                                 (det.belImposto.belIss.Clistserv != null ? new XElement(pf + "cListServ", det.belImposto.belIss.Clistserv.ToString()) : null),
                                 (det.belImposto.belIss.cSitTrib != null ? new XElement(pf + "cSitTrib", det.belImposto.belIss.cSitTrib.ToString()) : null)) : null)), // NFe_2.0 Tratar item


                             //-----------INFADPROD-------------//

                             (det.belInfadprod != null ?
                             (det.belInfadprod.Infadprid != null ? new XElement(pf + "infAdProd", det.belInfadprod.Infadprid.ToString()) : null) : null))); //Danner - o.s. sem -21/12/2009

                        lcondet.Add(condet);
                    }
                    #endregion
                }
                catch (Exception x)
                {
                    throw new Exception("Nota de Sequência - " + sNota + "Erro na geração do XML, Regiao XML_Detalhes - " + x.Message);
                }
                #endregion

                //Total
                XContainer contotal;

                try
                {
                    belTotal objtotal = i[5] as belTotal;
                    #region XML_Total

                    contotal = (new XElement(pf + "total",
                                            (objtotal.belIcmstot != null ? new XElement(pf + "ICMSTot",
                                                  new XElement(pf + "vBC", objtotal.belIcmstot.Vbc.ToString("#0.00").Replace(",", ".")),//Danner - o.s. 24271 - 15/03/2010
                                                  new XElement(pf + "vICMS", objtotal.belIcmstot.Vicms.ToString("#0.00").Replace(",", ".")),
                                                  new XElement(pf + "vBCST", objtotal.belIcmstot.Vbcst.ToString("#0.00").Replace(",", ".")),
                                                  new XElement(pf + "vST", objtotal.belIcmstot.Vst.ToString("#0.00").Replace(",", ".")),
                                                  new XElement(pf + "vProd", objtotal.belIcmstot.Vprod.ToString("#0.00").Replace(",", ".")),
                                                  new XElement(pf + "vFrete", objtotal.belIcmstot.Vfrete.ToString("#0.00").Replace(",", ".")),
                                                  new XElement(pf + "vSeg", objtotal.belIcmstot.Vseg.ToString("#0.00").Replace(",", ".")),
                                                  new XElement(pf + "vDesc", objtotal.belIcmstot.Vdesc.ToString("#0.00").Replace(",", ".")),
                                                  new XElement(pf + "vII", objtotal.belIcmstot.Vii.ToString("#0.00").Replace(",", ".")),
                                                  new XElement(pf + "vIPI", objtotal.belIcmstot.Vipi.ToString("#0.00").Replace(",", ".")),
                                                  new XElement(pf + "vPIS", objtotal.belIcmstot.Vpis.ToString("#0.00").Replace(",", ".")),
                                                  new XElement(pf + "vCOFINS", objtotal.belIcmstot.Vcofins.ToString("#0.00").Replace(",", ".")),
                                                  new XElement(pf + "vOutro", objtotal.belIcmstot.Voutro.ToString("#0.00").Replace(",", ".")),
                                                  new XElement(pf + "vNF", objtotal.belIcmstot.Vnf.ToString("#0.00").Replace(",", "."))) : null),



                                            (objtotal.belIssqntot != null ? new XElement(pf + "ISSQNtot",
                                                new XElement(pf + "vServ", objtotal.belIssqntot.Vserv.ToString("#0.00").Replace(",", ".")),
                                                new XElement(pf + "vBC", objtotal.belIssqntot.Vbc.ToString("#0.00").Replace(",", ".")),
                                                new XElement(pf + "vISS", objtotal.belIssqntot.Viss.ToString("#0.00").Replace(",", ".")),
                                                (objtotal.belIssqntot.Vpis != 0 ? new XElement(pf + "vPIS", objtotal.belIssqntot.Vpis.ToString("#0.00").Replace(",", ".")) : null),
                                                (objtotal.belIssqntot.Vcofins != 0 ? new XElement(pf + "vCOFINS", objtotal.belIssqntot.Vcofins.ToString("#0.00").Replace(",", ".")) : null)) : null)));
                    //(objtotal.belRetTrib != null ? new XElement(pf + "retTrib",
                    //                                   new XElement(pf + "vRetPIS", objtotal.belRetTrib.Vretpis.ToString("#0.00").Replace(",", ".")),
                    //                                   new XElement(pf + "vRetCOFINS", objtotal.belRetTrib.Vretcofins.ToString("#0.00").Replace(",", ".")),
                    //                                   new XElement(pf + "vRetCSLL", objtotal.belRetTrib.Vretcsll.ToString("#0.00").Replace(",", ".")),
                    //                                   new XElement(pf + "vBCIRRF", objtotal.belRetTrib.Vbcirrf.ToString("#0.00"),
                    //                                   new XElement(pf + "vIRRF", objtotal.belRetTrib.Virrf.ToString("#0.00").Replace(",", ".")),
                    //                                   new XElement(pf + "vBCRetPrev", objtotal.belRetTrib.Vbcretprev.ToString("#0.00").Replace(",", ".")),
                    //                                   new XElement(pf + "vRetPrev", objtotal.belRetTrib.Vretprev.ToString("#0.00").Replace(",", "."))) : null)));

                    #endregion
                }
                catch (Exception x)
                {
                    throw new Exception("Nota de Sequência - " + sNota + "Erro na geração do XML, Regiao XML_Total - " + x.Message);
                }
                //Fim - Total

                //Frete
                XContainer contransp;
                belTransp objtransp;
                try
                {
                    objtransp = i[6] as belTransp;
                    #region XML_Transporte

                    contransp = (new XElement(pf + "transp",
                                               new XElement(pf + "modFrete", objtransp.Modfrete.ToString()),
                                               new XElement(pf + "transporta",
                                                   (objtransp.belTransportadora.Cnpj != null ? new XElement(pf + "CNPJ", objtransp.belTransportadora.Cnpj.ToString()) :
                                                                                               (objtransp.belTransportadora.Cpf != null ? new XElement(pf + "CPF", objtransp.belTransportadora.Cpf.ToString()) : null)),
                                                   (objtransp.belTransportadora.Xnome != null ? new XElement(pf + "xNome", objtransp.belTransportadora.Xnome.ToString()) : null),
                                                   (objtransp.belTransportadora.Ie != null ? new XElement(pf + "IE", objtransp.belTransportadora.Ie.ToString()) : null),
                                                   (objtransp.belTransportadora.Xender != null ? new XElement(pf + "xEnder", objtransp.belTransportadora.Xender.ToString()) : null),
                                                   (objtransp.belTransportadora.Xmun != null ? new XElement(pf + "xMun", objtransp.belTransportadora.Xmun.ToString()) : null),
                                                   (objtransp.belTransportadora.Uf != null ? new XElement(pf + "UF", objtransp.belTransportadora.Uf.ToString()) : null)),
            (objtransp.belRetTransp != null ? (new XElement(pf + "retTransp",
                                                   new XElement(pf + "vServ", objtransp.belRetTransp.Vserv.ToString("#0.00").Replace(',', '.')),
                                                   new XElement(pf + "vBCRet", objtransp.belRetTransp.Vbvret.ToString("#0.00").Replace(',', '.')),
                                                   new XElement(pf + "pICMSRet", objtransp.belRetTransp.Picmsret.ToString()),
                                                   new XElement(pf + "vICMSRet", objtransp.belRetTransp.Vicmsret.ToString("#0.00").Replace(',', '.')),
                                                   new XElement(pf + "CFOP", objtransp.belRetTransp.Cfop.ToString()),
                                                   new XElement(pf + "cMunFG", objtransp.belRetTransp.Cmunfg.ToString()))) : null),
            (objtransp.belVeicTransp != null ? (new XElement(pf + "veicTransp",
                                                   (objtransp.belVeicTransp.Placa != null ? new XElement(pf + "placa", objtransp.belVeicTransp.Placa.ToString()) : null),
                                                   (objtransp.belVeicTransp.Uf != null ? new XElement(pf + "UF", objtransp.belVeicTransp.Uf.ToString()) : null),
                                                   (objtransp.belVeicTransp.Rntc != null ? new XElement(pf + "RNTC", objtransp.belVeicTransp.Rntc.ToString()) : null))) : null),
               (objtransp.belReboque != null ? new XElement(pf + "reboque",
                                                   (objtransp.belReboque.Placa != null ? new XElement(pf + "placa", objtransp.belReboque.Placa.ToString()) : null),
                                                   (objtransp.belReboque.Uf != null ? new XElement(pf + "UF", objtransp.belReboque.Uf.ToString()) : null),
                                                   (objtransp.belReboque.Rntc != null ? new XElement(pf + "RNTC", objtransp.belReboque.Rntc.ToString()) : null)) : null),
                   (objtransp.belVol != null ? new XElement(pf + "vol",
                                                   (objtransp.belVol.Qvol > 0 ? new XElement(pf + "qVol", objtransp.belVol.Qvol.ToString("#")) : null),
                                                   (objtransp.belVol.Esp != "" ? new XElement(pf + "esp", objtransp.belVol.Esp.ToString()) : null),
                                                   (objtransp.belVol.Marca != "" ? new XElement(pf + "marca", objtransp.belVol.Marca.ToString()) : null),
                                                   (objtransp.belVol.Nvol != null ? new XElement(pf + "nVol", objtransp.belVol.Nvol.ToString()) : null),//Danner - o.s. 24385 - 26/04/2010
                                                   new XElement(pf + "pesoL", objtransp.belVol.PesoL.ToString("#0.000").Replace(",", ".")),
                                                   new XElement(pf + "pesoB", objtransp.belVol.PesoB.ToString("#0.000").Replace(",", "."))) : null),
               (objtransp.belLacres != null ? new XElement(pf + "lacres",
                                                   new XElement(pf + "nLacre", "")) : null)));



                    #endregion
                }
                catch (Exception x)
                {
                    throw new Exception("Nota de Sequência - " + sNota + "Erro na geração do XML, Regiao XML_Transporte - " + x.Message);
                }
                //Fim - Frete

                //Duplicata
                XContainer concobr = null;
                belCobr objcob;
                try
                {
                    if (belStatic.sNomeEmpresa != "LORENZON")
                    {
                        objcob = i[7] as belCobr;
                        #region XML_Cobrança
                        concobr = (new XElement(pf + "cobr",
                                                  new XElement(pf + "fat",
                                                      new XElement(pf + "nFat", objcob.belFat.Nfat.ToString()),
                                                      (objcob.belFat.Vorig != 0 ? new XElement(pf + "vOrig", objcob.belFat.Vorig.ToString("#0.00").Replace(",", ".")) : null),
                                                      (objcob.belFat.Vdesc != null && objcob.belFat.Vdesc != 0 ? new XElement(pf + "vDesc", objcob.belFat.Vdesc.ToString("#0.00").Replace(",", ".")) : null),
                                                      (objcob.belFat.Vliq != 0 ? new XElement(pf + "vLiq", objcob.belFat.Vliq.ToString("#0.00").Replace(",", ".")) : null)),
                                                      (objcob.belFat.belDup != null ? from dup in objcob.belFat.belDup
                                                                                      select new XElement(pf + "dup", new XElement(pf + "nDup", dup.Ndup.ToString()),
                                                                                             new XElement(pf + "dVenc", dup.Dvenc.ToString("yyyy-MM-dd")),
                                                                                             (belStatic.sNomeEmpresa != "LORENZON" ? new XElement(pf + "vDup", dup.Vdup.ToString("#0.00").Replace(",", ".")) : null)) : null)));

                        #endregion
                    }
                }
                catch (Exception x)
                {
                    throw new Exception("Nota de Sequência - " + sNota + "Erro na geração do XML, Region XML_Cobrança - " + x.Message);
                }

                //Fim - Duplicata

                //Obs
                XContainer conobs;
                belInfAdic objobs;
                try
                {
                    objobs = i[8] as belInfAdic;
                    #region XML_Obs

                    if (sUF.Equals("EX") && objobs.Infcpl == null)
                    {
                        objobs.Infcpl = "SEM OBSERVACAO";
                    }

                    conobs = new XElement(pf + "infAdic",
                                                (objobs.Infcpl != null ?
                                                new XElement(pf + "infCpl", objobs.Infcpl.ToString()) : null));
                    #endregion
                }
                catch (Exception x)
                {
                    throw new Exception("Nota de Sequência - " + sNota + "Erro na geração do XML,Regiao XML_Obs - " + x.Message);
                }
                //Fim - Obs

                //OS_25679

                #region Exporta
                XContainer conExporta = null;

                belExporta objExporta = i[9] as belExporta;

                if ((objExporta.Ufembarq != "") && (objExporta.Xlocembarq != ""))
                {
                    conExporta = new XElement(pf + "exporta",
                                                new XElement(pf + "UFEmbarq", objExporta.Ufembarq),
                                                new XElement(pf + "xLocEmbarq", objExporta.Xlocembarq));
                }

                #endregion

                //Uniao dos Containers
                try
                {

                    concabec.Add(coninfnfe);
                    coninfnfe.Add(conide);
                    conide.AddAfterSelf(conemit);
                    conemit.AddAfterSelf(condest);
                    condest.AddAfterSelf(contotal);
                    contotal.AddAfterSelf(contransp);

                    if (concobr != null)
                    {
                        contransp.AddAfterSelf(concobr);
                        if (objobs.Infcpl != null)
                            concobr.AddAfterSelf(conobs);
                    }
                    else
                    {
                        if (objobs.Infcpl != null)
                            contransp.AddAfterSelf(conobs);
                    }
                    if (conExporta != null)
                    {
                        conobs.AddAfterSelf(conExporta);
                    }

                    foreach (XElement x in lcondet)
                    {
                        contotal.AddBeforeSelf(x);
                    }
                }
                catch (Exception x)
                {
                    throw new Exception("Nota de Sequência - " + sNota + "Erro na montagem do XML, União dos Containers - " + x.Message);
                }
                try
                {
                    AssinaNFeXml Assinatura = new AssinaNFeXml();
                    string nfe = Assinatura.ConfigurarArquivo(concabec.ToString(), "infNFe", cert);
                    nfes.Add(nfe);
                    XElement xnfe = XElement.Parse(nfe);
                    XDocument xdocsalvanfesemlot = new XDocument(xnfe);

                    DirectoryInfo dPastaData = new DirectoryInfo(belStaticPastas.ENVIO + "\\" + sNFe.Substring(5, 4));
                    if (!dPastaData.Exists) { dPastaData.Create(); }
                    if (sFormaEmiNFe.Equals("2"))
                    {
                        xdocsalvanfesemlot.Save(belStaticPastas.CONTINGENCIA + "\\" + sNFe.Replace("NFe", "") + "-nfe.xml");
                    }
                    else
                    {
                        xdocsalvanfesemlot.Save(belStaticPastas.ENVIO + "\\" + sNFe.Substring(5, 4) + "\\" + sNFe.Replace("NFe", "") + "-nfe.xml"); // OS_25024
                    }
                    //StreamWriter swnfe = new StreamWriter(glob.LeRegWin("PastaXmlEnvio").ToString() + "\\" + sNFe.Replace("NFe", "") + "-nfe.xml");
                    //swnfe.Write(nfe);
                    //swnfe.Close();
                }
                catch (Exception x)
                {
                    throw new Exception("Nota de Sequência - " + sNota + "Erro ao assinar a nfe de sequencia " + sNota + x.Message);
                }

                iCount++;
            }

            //Concatenando as NFes.
            string sXmlComp = "";
            //Junta todos os XML's em texto 
            foreach (var i in nfes)
            {
                sXmlComp = sXmlComp + i;
            }
            //Estou inserindo o enviNFe pois se eu transformar o arquivo xml assinado em xml e depois em texto usando um toString,
            //a assinatura se torna invalida. Então depois de assinado do trabalho em forma de texto como xml ateh envia-lo pra fazenda.                        
            sXmlfull = "<?xml version=\"1.0\" encoding=\"utf-8\"?><enviNFe xmlns=\"http://www.portalfiscal.inf.br/nfe\" versao=\"2.00\"><idLote>" +
                        sNomeArq.Substring(7, 15) + "</idLote>" + sXmlComp + "</enviNFe>";

            //Grava
            StreamWriter sw = new StreamWriter(sPath);
            sw.Write(sXmlfull);
            sw.Close();

            #region Valida_Xml

            Globais getschema = new Globais();

            //string sXml = File.OpenText(sPath).ReadToEnd();

            XmlSchemaCollection myschema = new XmlSchemaCollection();

            XmlValidatingReader reader;

            //Danner - o.s. 23732 - 06/11/2009

            try
            {
                XmlParserContext context = new XmlParserContext(null, null, "", XmlSpace.None);

                reader = new XmlValidatingReader(sXmlfull, XmlNodeType.Element, context);

                myschema.Add("http://www.portalfiscal.inf.br/nfe", belStaticPastas.SCHEMA_NFE + "\\enviNFe_v2.00.xsd");

                reader.ValidationType = ValidationType.Schema;

                reader.Schemas.Add(myschema);

                while (reader.Read())
                {

                }

            }
            catch (XmlException x)
            {
                File.Delete(sPath);
                throw new Exception(x.Message);
            }
            catch (XmlSchemaException x)
            {
                File.Delete(sPath);
                throw new Exception(x.Message);
            }

            //Fim - Danner - o.s. 23732 - 06/11/2009

            #endregion

        }