https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/linq/how-to-write-queries-on-xml-in-namespaces

public static int GetProgramId(string filePath)
{
int programId = ;
var element = XElement.Load(filePath); XNamespace xNamespace = element.GetDefaultNamespace(); XName tempXName1 = xNamespace + "appSettings";
var temp = element.Element(tempXName1); XName tempXName2 = xNamespace + "add";
var targetElement = temp?.Elements(tempXName2)
.FirstOrDefault(x => x.Attribute("key")?.Value == "ProgramID");
if (targetElement == null)
{
LogUtil.CreateLog(LogLevel.Error, $"Can not find ProgramID in appSettings section in {filePath}");
}
else
{
var valueAttribute = targetElement.Attribute("value");
if (valueAttribute == null)
{
LogUtil.CreateLog(LogLevel.Error,
$"Can not find value attribute in appSettings section with key = ProgramID in {filePath}");
}
else
{
programId = Convert.ToInt32(valueAttribute.Value);
}
} return programId;
}

read appSettings in configuration file by XElement with xmlns的更多相关文章

  1. The configuration file 'appsettings.json' was not found and is not optional

    问: .Net Core: Application startup exception: System.IO.FileNotFoundException: The configuration file ...

  2. 解决Scala Play框架在Git Bash运行的异常:Could not find configuration file ../framework/sbt/sbt.boot.properties

    Git Bash+ConEmu可以模拟Linux强大的命令行.不过在结合Scala和Play时,需要注意如下事项: 1. Scala的安装在64位操作系统下,默认会放在“C:\Program File ...

  3. Error: Cannot open main configuration file '//start' for reading! 解决办法

    当执行service nagios start启动nagios时,报错:Error: Cannot open main configuration file '//start' for reading ...

  4. phpmyadmin Wrong permissions on configuration file, should not be world writable!

    巴拉巴拉,实际场景是这样,因为有需要,所以想用django 做个rest服务给其他平台提供服务,发现以前正常的页面都无法运行,奇怪发现有一个页面提示连接不上mysql 难道mysql挂了,打开phpm ...

  5. springMVC+mybatis 进行单元测试时 main SqlSessionFactoryBean - Parsed configuration file: 'class path resource' 无限的读取xml文件

    今天终于写完的Dao层的操作,怀着无比激动的心情,进行单元测试,就在最后一个方法,对的就是最后一个方法,启动单元测试就会报以下错误: [2016-05-11 18:25:01,691] [WARN ] ...

  6. [Bug]IIs Cannot read configuration file due to insufficient permissions

    摘要 在部署站点的时候,遇到这样的问题Cannot read configuration file due to insufficient permissions 解决办法 在服务器上部署站点,浏览的 ...

  7. Nginx - Configuration File Syntax

    Configuration Directives The Nginx configuration file can be described as a list of directives organ ...

  8. How to find configuration file MySQL uses?

    http://www.dbasquare.com/2012/04/01/how-to-find-mysql-configuration-file/ A customer called me today ...

  9. This configuration file was broken by system-config-keyboard

    posts • Page of problem with startx Postby evarie » // :: Normally i can get started with the x wind ...

随机推荐

  1. *AtCoder Regular Contest 096F - Sweet Alchemy

    $n \leq 50$的树,每个点有权值,现要选点(可多次选一个点)使点数尽量多,如下限制:选的总权值不超过$C \leq 1e9$:$c_i$表示$i$选的次数,$p_i$表示$i$的父亲,那么$c ...

  2. hdu 4882 /按排顺序使序列最优问题

    题意: 安排一个序列,该序列每个数有俩个属性:t[i].val[i].计算一个点的价值:到目前为止的总时间*val[i].,,求  安排顺序后使得 计算所有点的价值之和最小. 思路:对于任意相邻俩项, ...

  3. .net core 使用 codegenerator 创建默认CRUD代码

    dotnet.exe aspnet-codegenerator controller --force --controllerName [controller-name] --relativeFold ...

  4. Codeforces 667C Reberland Linguistics【DFS】

    一道卡题意的题. 题目链接: http://codeforces.com/problemset/problem/667/C 题意: 一个串可以看成一个长度大于4的根,加上其后面的若干个相邻(in a ...

  5. T1077 多源最短路 codevs

    http://codevs.cn/problem/1077/ 时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold 题目描述 Description 已知n个点(n&l ...

  6. 第2章 CentOS网络配置

    一.配置说明 1.1 说明 1.本文以VM仅本机模式下与宿主机的网络配置为例. 1.2 达成目标 1.Windows能ping通centOS 2 centOS能够ping通Windows 3 cent ...

  7. Word中将文本框、图形对象中的文本边距调整

    在进行word的实际使用中,如下图制作流程图时,常常发现文字在图形对象中,老是显示不全,而且上部却空出很多距离.此时可以通过设置形状格式--文本框 --- 上.下编辑进行设置. 可以完美解决文本框中文 ...

  8. java cocurrent并发包

    1. java.util.concurrent - Java 并发工具包Java 5 添加了一个新的包到 Java 平台,java.util.concurrent 包.这个包包含有一系列能够让 Jav ...

  9. Go -- 并发编程的两种限速方法

    引子 golang提供了goroutine快速实现并发编程,在实际环境中,如果goroutine中的代码要消耗大量资源时(CPU.内存.带宽等),我们就需要对程序限速,以防止goroutine将资源耗 ...

  10. kafka的安装和使用;kafka常用操作命令

    kafka:基于发布/订阅的分布式消息系统.数据管道:最初用来记录活动数据--包括页面访问量(Page View).被查看内容方面的信息以及搜索情况等内容和运营数据--服务器的性能数据(CPU.IO使 ...