Example #1
0
        public static string CreateXML(UISettingsCollection ui)
        {
            //if (File.Exists("settings.xml"))
            //{
            //    File.Delete("settings.xml");
            //}

            XmlDocument xmlDoc = new XmlDocument();

            // Initializes a new instance of the XmlDocument class.
            XmlSerializer xmlSerializer = new XmlSerializer(ui.GetType());

            // Creates a stream whose backing store is memory.
            using (MemoryStream xmlStream = new MemoryStream())
            {
                xmlSerializer.Serialize(xmlStream, ui);
                xmlStream.Position = 0;
                //Loads the XML document from the specified string.
                xmlDoc.Load(xmlStream);
                //xmlDoc.Save("settings.xml");
                xmlStream.Close();

                //using (FileStream fs = new FileStream("settings.xml", FileMode.OpenOrCreate))
                //{
                //    XmlSerializer serializer = new XmlSerializer(ui.GetType());
                //    serializer.Serialize(fs, ui);
                //}

                return(xmlDoc.InnerXml);
            }
        }
Example #2
0
        public static UISettingsCollection CreateObject(XmlDocument XMLString, UISettingsCollection ui)
        {
            UISettingsCollection ui1 = new UISettingsCollection();

            if (XMLString != null)
            {
                XmlSerializer oXmlSerializer = new XmlSerializer(ui.GetType());

                XmlNodeReader reader = null;

                try
                {
                    reader = new XmlNodeReader(XMLString);

                    ui1 = oXmlSerializer.Deserialize(reader) as UISettingsCollection;
                    //initially deserialized, the data is represented by an object without a defined type
                }
                finally
                {
                    if (reader != null)
                    {
                        reader.Close();
                    }
                }
                return(ui1);
            }
            else
            {
                return(ui);
            }
        }
Example #3
0
        public static XmlDocument CreateXML(UISettingsCollection ui)
        {
            XmlDocument xmlDoc = new XmlDocument();

            // Initializes a new instance of the XmlDocument class.
            XmlSerializer xmlSerializer = new XmlSerializer(ui.GetType());

            // Creates a stream whose backing store is memory.
            using (MemoryStream xmlStream = new MemoryStream())
            {
                try
                {
                    xmlSerializer.Serialize(xmlStream, ui);
                    xmlStream.Position = 0;
                    //Loads the XML document from the specified string.
                    xmlDoc.Load(xmlStream);
                    //xmlDoc.Save("settings.xml");
                }
                finally
                {
                    if (xmlStream != null)
                    {
                        xmlStream.Close();
                    }
                }
            }
            return(xmlDoc);
        }
Example #4
0
        public static UISettingsCollection CreateObject(string XMLString, UISettingsCollection ui)
        {
            UISettingsCollection ui1 = new UISettingsCollection();

            if (!XMLString.Equals(""))
            {
                XmlSerializer oXmlSerializer = new XmlSerializer(ui.GetType());
                //The StringReader will be the stream holder for the existing XML file
                ui1 = oXmlSerializer.Deserialize(new StringReader(XMLString)) as UISettingsCollection;
                //initially deserialized, the data is represented by an object without a defined type
                return(ui1);
            }
            else
            {
                return(ui);
            }
        }