码迷,mamicode.com
首页 > 其他好文 > 详细

LINQ

时间:2020-06-02 10:58:49      阅读:56      评论:0      收藏:0      [点我收藏+]

标签:lin   school   ring   loop   move   ESS   reader   code   doc   

XML处理

1.How to create xml ?

            XDocument customer =
            new XDocument(
                new XDeclaration("1.0", "UTF-16", "yes"),
                new XElement("customer",
                    new XAttribute("id", "C01"),
                    new XElement("firstName", "Paolo"),
                    new XElement("lastName", "Pialorsi"),
                    new XElement("addresses",
                        new XElement("address",
                            new XAttribute("type", "email"),
                            "paolo@devleap.it"),
                    new XElement("address",
                        new XAttribute("type", "url"),
                            "http://www.devleap.it/"),
                    new XElement("address",
                        new XAttribute("type", "home"),
                            "Brescia - Italy"))));    

LINQ create xml document  is very easy,and clearly.

2.How to create xml in loop

            //1.Declare Xdocument and have to set root node
            XDocument Content =
            new XDocument(
                new XElement("json")
            );

            //2.Add element to document
            XAttribute ID = new XAttribute("id", 1);
            XElement XmlElement = new XElement("School", ID, "南十三大学");
            Content.Root.Add(XmlElement);

3.How to remove all nodes attributes?

Content.Descendants().Attributes().Remove();

4.XmlReader how to read xml document content?

            XmlReader reader = Content.Root.CreateReader();
            reader.MoveToContent();
            string result = reader.ReadInnerXml();

 

LINQ

标签:lin   school   ring   loop   move   ESS   reader   code   doc   

原文地址:https://www.cnblogs.com/tangpeng97/p/13029730.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!