C# 3.0 LINQ to XML
2013-09-29 16:49
239 查看
高级转换:
static IEnumerable<XElement> ExpandPaths (IEnumerable<string> paths) { var brokenUp = from path in paths let split = path.Split (new char[] { '\\' }, 2) orderby split[0] select new { name = split[0], remainder = split.ElementAtOrDefault (1) }; IEnumerable<XElement> files = from b in brokenUp where b.remainder == null select new XElement ("file", b.name); IEnumerable<XElement> folders = from b in brokenUp where b.remainder != null group b.remainder by b.name into grp select new XElement ("folder", new XAttribute ("name", grp.Key), ExpandPaths (grp) ); return files.Concat (folders); } static void RunQuery() { XElement project = XElement.Load ("myProjectFile.csproj"); XName ns = project.Name.Namespace; IEnumerable<string> paths = from compileItem in project.Elements (ns + "ItemGroup").Elements (ns + "Compile") let include = compileItem.Attribute ("Include") where include != null select include.Value; XElement query = new XElement ("Project", ExpandPaths (paths)); }
相关文章推荐
- C# 3.0 LINQ to XML
- C# LINQ to XML应用介绍
- C#基础精华06(Linq To XML,读取xml文件,写入xml)
- [C#]Linq To Xml 介绍- 转
- C#基础巩固(3)-Linq To XML 读取XML
- C# LINQ to XML
- C# LINQ to XML
- C#使用LINQ to XML操作XML实例
- xml to linq C#实例 类和xml文件互转换
- [C#]Linq To Xml 实例操作- 转
- 【原创】C# Linq to XML
- C# Linq To XML 读取XML,修改属性
- C#基础巩固(2)-Linq To XML创建XML
- C#学习之Linq to Xml
- C# LINQ to XML
- C#程序中使用LINQ to XML来查询XML格式数据的实例
- C#新手入门代码 LINQ TO XML xattribute的用法示例
- C# 2008 学习笔记 - LINQ to XML
- c# linq to xml 获取某节点属性总数
- C# linq to xml