示例#1
0
        public static void Test()
        {
            Console.WriteLine("++++++++++++XmlSerializerTest++++++++++++++");

            RegularExpressionsElement element = new RegularExpressionsElement();

            element.Username = "******";
            element.Password = "******";
            XmlSerializer <RegularExpressionsElement> serializer = new XmlSerializer <RegularExpressionsElement>();

            serializer.OmitXmlDeclaration = true;
            String xmlString = serializer.ToXmlString(element);

            Console.WriteLine("ToXmlString: \r\n {0}", xmlString);
            RegularExpressionsElement newElement = serializer.FromXmlString(xmlString);

            Console.WriteLine("Username:{0} Password:{1}", newElement.Username, newElement.Password);

            using (FileStream file = File.Create("RegularExpressions.xml"))
            {
                serializer.ToStream(element, file);
            }
            using (FileStream file = File.Open("RegularExpressions.xml", FileMode.Open))
            {
                newElement = serializer.FromStream(file);
                Console.WriteLine("Username:{0} Password:{1}", newElement.Username, newElement.Password);
            }
        }