public void GeraXmlEnvio() { try { AssinaNFeXml Assinatura = new AssinaNFeXml(); XDocument xdoc = new XDocument(); XNamespace pf = "http://www.portalfiscal.inf.br/nfe"; XContainer xContEnvEvento = new XElement(pf + "envEvento", new XAttribute("xmlns", "http://www.portalfiscal.inf.br/nfe"), new XAttribute("versao", objEnvEvento.versao), new XElement(pf + "idLote", objEnvEvento.id)); //List<string> ListaEventos = new List<string>(); objXmlsSeparados = new Dictionary<string, string>(); foreach (var obj in objEnvEvento.evento) { XContainer xConEvento = new XElement(pf + "evento", new XAttribute("xmlns", "http://www.portalfiscal.inf.br/nfe"), new XAttribute("versao", obj.versao), new XElement(pf + "infEvento", new XAttribute("Id", obj.idLote), new XElement(pf + "cOrgao", obj.infEvento.cOrgao), new XElement(pf + "tpAmb", obj.infEvento.tpAmb), new XElement(pf + (obj.infEvento.CNPJ != "" ? "CNPJ" : "CPF"), (obj.infEvento.CNPJ != "" ? obj.infEvento.CNPJ : obj.infEvento.CPF)), new XElement(pf + "chNFe", obj.infEvento.chNFe), new XElement(pf + "dhEvento", obj.infEvento.dhEvento),//-02:00 new XElement(pf + "tpEvento", obj.infEvento.tpEvento), new XElement(pf + "nSeqEvento", obj.infEvento.nSeqEvento), new XElement(pf + "verEvento", obj.infEvento.verEvento), new XElement(pf + "detEvento", new XAttribute("versao", obj.versao), new XElement(pf + "descEvento", obj.infEvento.detEvento.descEvento), new XElement(pf + "xCorrecao", obj.infEvento.detEvento.xCorrecao), new XElement(pf + "xCondUso", obj.infEvento.detEvento.xCondUso)))); // ListaEventos.Add(Assinatura.ConfigurarArquivo(xConEvento.ToString(), "infEvento", cert)); objXmlsSeparados.Add(obj.infEvento.chNFe, Assinatura.ConfigurarArquivo(xConEvento.ToString(), "infEvento", cert)); } string sEventos = ""; foreach (KeyValuePair<string, string> sInfEvento in objXmlsSeparados) { sEventos += sInfEvento.Value; //xContEnvEvento.Add(XElement.Parse(sInfEvento, LoadOptions.PreserveWhitespace)); } sXMLfinal = "<?xml version=\"1.0\" encoding=\"utf-8\"?><envEvento xmlns=\"http://www.portalfiscal.inf.br/nfe\" versao=\"1.00\"><idLote>" + objEnvEvento.id.ToString() + "</idLote>" + sEventos + "</envEvento>"; #region Valida_Xml| HLP.bel.NFe.GeraXml.Globais getschema = new bel.NFe.GeraXml.Globais(); XmlValidatingReader reader; try { XmlSchemaCollection myschema = new XmlSchemaCollection(); myschema.Add("http://www.portalfiscal.inf.br/nfe", belStaticPastas.SCHEMA_CCE + "\\envCCe_v1.00.xsd"); XmlParserContext context = new XmlParserContext(null, null, "", XmlSpace.None); reader = new XmlValidatingReader(sXMLfinal, XmlNodeType.Element, context); 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; } }