zoukankan      html  css  js  c++  java
  • LINQ

    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();
  • 相关阅读:
    二叉树的镜像
    判断树B是不是树A的子结构
    LeetCode-21. Merge Two Sorted Lists
    LeetCode-Reverse Linked List I & II
    LeetCode-Permutations & Permutations II
    Linux常用命令
    Mac OS 快捷键
    Git 常用命令
    SVM参数寻优:grid search
    转载:Normal Equation证明及应用
  • 原文地址:https://www.cnblogs.com/tangpeng97/p/13029730.html
Copyright © 2011-2022 走看看