/// <summary> /// Retorna el xml del comprobante en formato string /// </summary> /// <param name="objetoComprobante"></param> /// <returns></returns> public static string GenerarXmlComprobante32(Modelos.Cfdi32.Comprobante objetoComprobante) { //Prefix NameSpaces - cfdi XmlSerializerNamespaces nsCfdi = new XmlSerializerNamespaces(); nsCfdi.Add("cfdi", "http://www.sat.gob.mx/cfd/3"); nsCfdi.Add("xsi", "http://www.w3.org/2001/XMLSchema-instance"); //XmlAttribute attr = doc.CreateAttribute("xsi", "schemaLocation", " "); //attr.Value = "http://www.irs.goc/efile ReturnData941.xsd"; //returnData.Attributes.Append(attr); string result = ""; Encoding localEncoding = Encoding.UTF8; MemoryStream stream = null; stream = new MemoryStream(); // StreamWriter writer = new StreamWriter(stream); XmlSerializer serializer = new XmlSerializer(typeof(Modelos.Cfdi32.Comprobante)); using (StreamWriter w = new StreamWriter(stream)) { serializer.Serialize(w, objetoComprobante, nsCfdi); result = localEncoding.GetString(stream.ToArray(), 0, (int)stream.Length); } return(result); }
public static string GenerarXmlComprobante323(Modelos.Cfdi32.Comprobante objetoComprobante) { XmlSerializerNamespaces nameSpaces = new XmlSerializerNamespaces(); nameSpaces.Add("xsi", "http://www.w3.org/2001/XMLSchema-instance"); nameSpaces.Add("la", "myDomain.com"); //XmlSerializer xmlser = new XmlSerializer(typeof(Report)); //using (System.IO.MemoryStream ms = new System.IO.MemoryStream()) //{ // xmlser.Serialize(ms, this, nameSpaces); // // return new UTF8Encoding().GetString(ms.ToArray()); //} ////****************************************************************************************** XmlSerializerNamespaces ns = new XmlSerializerNamespaces(); //ns.Add("xxa", "http://www.w3.org/2001/XMLSchema-instance"); ns.Add("la", "http://www.sat.gob.mx/cfd/3/nomi"); string result = ""; Encoding localEncoding = Encoding.UTF8; MemoryStream stream = null; stream = new MemoryStream(); // StreamWriter writer = new StreamWriter(stream); XmlSerializer serializer = new XmlSerializer(typeof(Modelos.Cfdi32.Comprobante)); using (StreamWriter w = new StreamWriter(stream)) { serializer.Serialize(w, objetoComprobante, ns); result = localEncoding.GetString(stream.ToArray(), 0, (int)stream.Length); } return(result); }