zoukankan      html  css  js  c++  java
  • LINQ to XML

    这套机制将加快读写XML文档的效率,以及可以直接利用LINQ进行查询。

    现在有一个专门的System.Xml.Linq的命名空间

                XDocument srcTree = new XDocument(
                    new XComment("This is a comment"),
                    new XElement("Root",
                        new XElement("Child1", "data1"),
                        new XElement("Child2", "data2"),
                        new XElement("Child3", "data3"),
                        new XElement("Child2", "data4"),
                        new XElement("Info5", "info5"),
                        new XElement("Info6", "info6"),
                        new XElement("Info7", "info7"),
                        new XElement("Info8", "info8"),
                        new XElement("Test","Chenxizhang",new XAttribute("ID",10248))
                    )
                );
     
                Console.WriteLine(srcTree);
     
                XDocument doc = new XDocument(
                    new XComment("This is a comment"),
                    new XElement("Root",
                        from el in srcTree.Element("Root").Elements()
                        where ((string)el).StartsWith("data")
                        select el
                    )
                );
                Console.WriteLine(doc);
                Console.Read();

    使用命名空间的例子

    http://msdn.microsoft.com/zh-tw/library/bb387075.aspx

                XNamespace aw = "http://www.adventure-works.com";
    
               XElement root = new XElement(aw + "Root",new XAttribute(XNamespace.Xmlns + "aw", "http://www.adventure-works.com"),new XElement(aw + "Child", "child content"));
                Console.WriteLine(root);
    
                Console.Read();
  • 相关阅读:
    【leetcode】Linked List Cycle
    wordnet的一些入门性介绍
    Wordnet的一些简单使用
    第九章:图论和网络爬虫
    自动文档摘要技术简介
    20169202 2016-2017-2《TCP/IP协议攻击》实验总结--十一周
    20169202 2016-2017-2《移动平台》第十一周学习总结
    20169202 2016-2017-2《网络攻防》第十一周学习总结
    20169202 2016-2017-2《移动平台》第十周实验总结
    20169202 2016-2017-2《网络攻防》第十周云班课实验总结
  • 原文地址:https://www.cnblogs.com/chenxizhang/p/1320505.html
Copyright © 2011-2022 走看看