xml


using System.Xml;
using System.Xml.XPath;
using System.Runtime.Serialization.Json;
using System.Runtime.Serialization;
using System.IO;
using System.Xml.Serialization;

 

protected void act_test(object sender, EventArgs e)
        {
            //string xml_str = "";

            //xml_str = xml_str + "<param>";
            //xml_str = xml_str + "<type>1</type>";
            //xml_str = xml_str + "<para>";
            //xml_str = xml_str + "<name>asdfsdf1</name>";
            //xml_str = xml_str + "<value>asdfzzz1</value>";
            //xml_str = xml_str + "</para>";
            //xml_str = xml_str + "<para>";
            //xml_str = xml_str + "<name>asdfsdf2</name>";
            //xml_str = xml_str + "<value>asdfzzz2</value>";
            //xml_str = xml_str + "</para>";
            //xml_str = xml_str + "</param>";

            //XmlDataDocument doc = new XmlDataDocument();
            //doc.LoadXml(xml_str);

            //XmlNodeList ndurl_list = doc.SelectNodes(".//para");
            //if (ndurl_list != null)
            //{
            //    foreach (XmlNode para_node in ndurl_list)
            //    {
            //        XmlNode name = para_node.SelectSingleNode(".//name");
            //        string name_str = name.InnerText;

            //        XmlNode value = para_node.SelectSingleNode(".//value");
            //        string value_str = value.InnerText;
            //    }
            //}
            Action<object> log = o => Console.WriteLine(o);
            Func<int, int, int> add = (x, y) => x + y;

            var p1 = new Person
            {
                Age = 12,
                Alive = true,
                Name = "lj",
                FavoriteFilms = new[] { "Up", "Avatar" }
            };
            var p2 = new Person() { Age = 28, Name = "cy", Child = p1 };

            // 序列化
            var jsonString = this.stringify(new[] { p1, p2 });
            log(jsonString == this.stringify(new List<Person>() { p1, p2 }));   //true
            log(jsonString);
            // 反序列化,泛型集合
            List<Person> plist = this.parse<List<Person>>(jsonString);
            // 数组转换            
            this.parse<Person[]>(jsonString);

            string ccc = XmlSerialize<List<Person>>(plist);
            //XmlDictionaryReader reader = JsonReaderWriterFactory.CreateJsonReader(Encoding.UTF8.GetBytes(jsonString), XmlDictionaryReaderQuotas.Max);
            //XmlDocument doc = new XmlDocument();
            //doc.Load(reader);
        }

你可能感兴趣的:(xml)