本文介绍了如何使用LINQ to XML查询XML文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我试图从给定的项目文件中提取所有条件编译constsants。该文件有几个 PropertyGroup 元素,如下所示: < PropertyGroup 条件 = '$(配置)| $(平台)'=='调试| AnyCPU' > < DebugSymbols > true < / DebugSymbols > < DebugType > 完整< / DebugType > < 优化 > false < /优化 > < OutputPath > bin \Debug \ < ; / OutputPath > < DefineConstants > DEBUG; TRACE < / DefineConstants > < ErrorReport > 提示< / ErrorRepo rt > < WarningLevel > 4 < / WarningLevel > < / PropertyGroup > 我第一次尝试Linq到Sql都给了我所有节点或者没有。我可以运行什么查询: (a)获取所有 DefineConstants 元素,但包含其父元素查询,因为我需要条件属性,或 (b)获取所有 PropertyGroup 具有 DefineConstants 子元素的元素并包含这些子元素。 我正在尝试构建条件编译字典常量,所以下次遇到像 DEVIL_FROG_POTATO_GREEN 这样的常量时,你可以弹出我的字典窗口并阅读或希望写下它为别人做的事情。解决方案 I am trying to extract all conditional compilation constsants from a given project file. The file has several PropertyGroup elements like this:<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "><DebugSymbols>true</DebugSymbols><DebugType>full</DebugType><Optimize>false</Optimize><OutputPath>bin\Debug\</OutputPath><DefineConstants>DEBUG;TRACE</DefineConstants><ErrorReport>prompt</ErrorReport><WarningLevel>4</WarningLevel></PropertyGroup>My first attempts at Linq to Sql all gave me all nodes, or none. What queries can I run to:(a) get all DefineConstants elements, but include their parent element in the query, because I need the Condition attribute, or(b) get all PropertyGroup elements that have DefineConstants children and include this children.I am trying to build a dictionary of conditional compilation constants, so next time you come across a constant like DEVIL_FROG_POTATO_GREEN, you can just pop open my dictionary window and read, or hopefully, write what it does for others. 解决方案 这篇关于如何使用LINQ to XML查询XML文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-13 21:22