Exemple #1
0
        // public PathsCertificado ObjCfdi { get; set; }

        #region CFDI 3.2 Nomina 1.2

        private static string GenerarXml12(Modelos.Nomina12.Nomina objetoNomina)
        {
            string       result        = "";
            Encoding     LocalEncoding = Encoding.UTF8;
            MemoryStream stream        = null;

            stream = new MemoryStream();
            StreamWriter writer    = new StreamWriter(stream);
            string       xmlResult = "";

            XmlSerializerNamespaces nsNom12 = new XmlSerializerNamespaces();

            nsNom12.Add("nomina12", "http://www.sat.gob.mx/nomina12");
            nsNom12.Add("xsi", "http://www.w3.org/2001/XMLSchema-instance");

            XmlSerializer serializer = new XmlSerializer(typeof(Modelos.Nomina12.Nomina));

            //writer = new StreamWriter(stream, LocalEncoding);
            //serializer.Serialize(writer, nom);
            //var buffer = new byte[stream.Length];
            //stream.Read(buffer, 0, (int)stream.Length);
            //xmlResult = LocalEncoding.GetString(buffer);

            using (StreamWriter sw = new StreamWriter(stream))
            {
                serializer.Serialize(writer, objetoNomina, nsNom12);
                xmlResult = LocalEncoding.GetString(stream.ToArray(), 0, (int)stream.Length);
            }

            return(xmlResult);
        }
Exemple #2
0
        /// <summary>
        /// Retorna Elemento xml de la nomina para integrarse al xml de cfdi 3.2
        /// </summary>
        /// <param name="objetoNomina"></param>
        /// <returns></returns>
        public static XmlElement GetXmlElement(Modelos.Nomina12.Nomina objetoNomina)
        {
            var result = GenerarXml12(objetoNomina);

            XmlDocument xdoc = new XmlDocument();

            xdoc.LoadXml(result);

            return(xdoc.DocumentElement);
        }