Ejemplo n.º 1
0
        public string GetXMLFromObject(object o, string fileName)
        {
            StringWriter sw = new StringWriter();

            try
            {
                orders orders = new orders();
                orders.order = new complexTypeOrder[] { (complexTypeOrder)o };

                XmlTextWriter tw = new XmlTextWriter(sw);
                tw.Formatting  = System.Xml.Formatting.Indented;
                tw.Indentation = 4;

                XmlSerializer ser = new XmlSerializer(orders.GetType());
                ser.Serialize(tw, orders);

                tw.Close();
                sw.Close();
                File.WriteAllText(fileName, sw.ToString());
            }
            catch (Exception ex)
            {
                //Handle Exception Code
            }
            return(sw.ToString());
        }