zoukankan      html  css  js  c++  java
  • Linq to xml:流式处理 XmlReader

    IEnumerable<string> grandChildData =
                    from el in StreamRootChildDoc(new StringReader(markup))
                    where (int)el.Attribute("Key") > 1
                    select (string)el.Element("GrandChild");

                foreach (string str in grandChildData)
                {
                    Console.WriteLine(str);
                }

    处理函数

     static IEnumerable<XElement> StreamRootChildDoc(StringReader stringReader)
            {
                using (XmlReader reader = XmlReader.Create(stringReader))
                {
                    reader.MoveToContent();
                    // Parse the file and display each of the nodes.
                    while (reader.Read())
                    {
                        switch (reader.NodeType)
                        {
                            case XmlNodeType.Element:
                                if (reader.Name == "Child")
                                {
                                    XElement el = XElement.ReadFrom(reader) as XElement;
                                    if (el != null)
                                        yield return el;
                                }
                                break;
                        }
                    }
                }
            }

    关于作者: 王昕(QQ:475660) 在广州工作生活30余年。十多年开发经验,在Java、即时通讯、NoSQL、BPM、大数据等领域较有经验。
    目前维护的开源产品:https://gitee.com/475660
  • 相关阅读:
    win7下new出的内存默认是无执行权限的
    【转】 C++获得系统时间,以及1970年1月1日到现在的毫秒数
    【收藏】获取系统安装软件(vc++源码)
    opencv编译以及测试
    Vim命令合集
    在SSMS中打开DTS Package
    秋日的阳光
    又一位部门同事离职
    不要让你的孩子成为留守儿童,更不让你的父母成为空巢老人
    又将有一位同事离职
  • 原文地址:https://www.cnblogs.com/starcrm/p/1362827.html
Copyright © 2011-2022 走看看