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. Linux(11):期中架构(3)--- SSH远程管理服务 & ansible 批量管理服务

    SSH远程管理服务 1. 远程管理服务知识介绍 # 1.1 SSH远程登录服务介绍说明 SSH是Secure Shell Protocol的简写,由 IETF 网络工作小组(Network Worki ...

  2. localStorage增删改查

    /** * 设置 本地缓存 */ export function setStorage(key, obj) { if (typeof obj === 'string') { localStorage. ...

  3. idea 自定义工具栏

    问题:在笔记本上面使用idea的时候,有时候,需要使用 Ctrl+Alt+左箭头 /  Ctrl+Alt+右箭头 跳转到 上一次,查看代码的问题,然而存在快捷冲突的时候,很蛋疼.下面是解决办法. 效果 ...

  4. msp430项目编程43

    msp430综合项目---蓝牙控制直流电机调速系统43 1.电路工作原理 2.代码(显示部分) 3.代码(功能实现) 4.项目总结

  5. 关于maven下载慢的问题

    昨天刚接触到maven,尝试在mac上配置maven时发现,下载速度极度缓慢,从网上找了些方法,总算是解决了问题. 修改${maven.home}/conf或者${user.home}/.m2文件夹下 ...

  6. Neo4j 第七篇:模式(Pattern)

    模式和模式匹配是Cypher的核心,使用模式来描述所需数据的形状,该模式使用属性图的结构来描述,通常使用小括号()表示节点,-->表示关系,-[]->表示关系和关系的类型,箭头表示关系的方 ...

  7. STL优先队列模板

    1. 优先队列 用途:按照某一个关键字对插入元素或删除元素后的数据集进行自动排序 复杂度: logN 2. 数据声明 (1)头文件:#include<queue> (2)声明:  prio ...

  8. T1553 互斥的数 codevs

    http://codevs.cn/problem/1553/ 题目描述 Description 有这样的一个集合,集合中的元素个数由给定的N决定,集合的元素为N个不同的正整数,一旦集合中的两个数x,y ...

  9. 洛谷P1061 Jam的计数法

    题目描述 Jam是个喜欢标新立异的科学怪人.他不使用阿拉伯数字计数,而是使用小写英文字母计数,他觉得这样做,会使世界更加丰富多彩.在他的计数法中,每个数字的位数都是相同的(使用相同个数的字母),英文字 ...

  10. centos安装配置nginx,ssl生产和配置教程

    [一]nginx安装nginx安装带ssl扩展: cd /usr/local/src #进入用户目录wget http://nginx.org/download/nginx-1.15.0.tar.gz ...