remove namespace from xml config file
从xml配置文件中移除命令空间
https://stackoverflow.com/questions/987135/how-to-remove-all-namespaces-from-xml-with-c
string xml = node.OuterXml;
//Regex below finds strings that start with xmlns, may or may not have :and some text, then continue with =
//and ", have a streach of text that does not contain quotes and end with ". similar, will happen to an attribute
// that starts with xsi.
string strXMLPattern = @"xmlns(:\w+)?=""([^""]+)""|xsi(:\w+)?=""([^""]+)""";
xml = Regex.Replace(xml, strXMLPattern, "");
/// <summary>
/// config section to remove in patch
/// </summary>
private List<string> _removeList; /// <summary>
/// appSettings will keep in patch(if exist in patch)
/// </summary>
private List<string> _usefulAppSettings; /// <summary>
/// xpath for appSettings section to remove in patch
/// </summary>
private string _appSettingsToRemove; private void InitIgnoreList()
{
InitAppSettingsToRemove();
_removeList = new List<string>
{
"/configuration/connectionStrings",
"/configuration/system.web/customErrors",
_appSettingsToRemove
};
} private void InitAppSettingsToRemove()
{
//xPath = "/configuration/appSettings/add[(@key!='CMSProgrammingLanguage' and @key!='WS.webservice') ]";
_usefulAppSettings = new List<string>
{
"CMSProgrammingLanguage",
"WS.webservice",
"ChartImageHandler",
"PageInspector:ServerCodeMappingSupport",
"ValidationSettings:UnobtrusiveValidationMode",
"LISALastUpdatedVersionTime",
"LISAUpdatedVersion"
};
var temp1 = "/configuration/appSettings/add[({0})]";
var temp2 = "@key!='{0}'"; //key not equal
var temp3 = string.Join(" and ", _usefulAppSettings.Select(x => string.Format(temp2, x)));
_appSettingsToRemove = string.Format(temp1, temp3);
}
remove namespace from xml config file的更多相关文章
- Create a custom configSection in web.config or app.config file
config file: <?xml version="1.0" encoding="utf-8" ?> <configuration> ...
- Modifying namespace in XML document programmatically
Modifying namespace in XML document programmatically static XElement stripNS(XElement root) { return ...
- MVC模式下unity配置,报错“No connection string named '**Context' could be found in the application config file”
写在前面: 第一次配置时好好的,后来第二次改到MVC模式,把依赖注入写成字典的单例模式时,由于新建的ORM(数据库映射模型EF),怎么弄都不用,一直报错"No connection str ...
- Camel routes in Spring config file
The normal spring bean definition configuration file, the xsi:schemaLocation only has two: beans and ...
- The web.config file for this project is missing the required DirectRequestModule.
The web.config file for this project is missing the required DirectRequestModule. 将应用程序集的模式由集成改为经典 ...
- Can not find connection pool config file
暂时未解决 checkActivation=====================true Can Not Parse ConnectionCfg! 2019/10/12-11:23:38 > ...
- [笔记]HAproxy reload config file with uninterrupt session
HAProxy is a high performance load balancer. It is very light-weight, and free, making it a great op ...
- error in config file "/etc/rabbitmq/rabbitmq.config"
记录一次RabbitMQ配置文件配置错误 error信息: dill@ubuntu-vm:/usr/share/doc/rabbitmq-server$ sudo /usr/lib/rabbitmq/ ...
- .NET错误The 'targetFramework' attribute in the <compilation> element of the Web.config file is used only to target version 4.0 and later of the .NET Framework
错误描述: The 'targetFramework' attribute in the <compilation> element of the Web.config file is u ...
随机推荐
- 分析器错误消息: 该配置节不能包含 CDATA 或文本元素。
原因当然是web.config配置文件中,有字符串文本了,估计不小心加上的一些字符,所以会报错,去掉就行,例如13行的s
- Redis系列(十)--集群cluster
在之前学习了Master-Slave.Sentinel模式,但是在某些情况下还是无法满足系统对QPS等要求,这时候就需要Cluster,Redis3.0支持了cluster 一.为什么使用Cluste ...
- 03Struts2基本使用流程
Struts2基本使用流程 1.新建web工程 2.引入struts2类库 3.创建并配置Struts2的核心控制器web.xml用来拦截客户端请求并将请求转发到相应的Action类中来处理 4.创建 ...
- Unity中带有alpha通道的视频叠加播放
问题: 如何让两个透明视频叠加播放 解决播放: 1:使用Unity自带的shader,shader代码如下所示 Shader "Unlit/MaskVideo" { Propert ...
- TWaver动画之雷达扫描效果
UI和功能是好的产品的两个重要因素,很多产品往往只注重功能上的设计,而忽略了UI.在这个“看脸”的时代,就算产品的功能很强大,如果UI跟不上步伐,你的产品都会在客户心中大打折扣.做安全和监控的项目中经 ...
- printf函数压栈(i++/i--,++i/--i) 终极解密
#include <stdio.h> void main() { ; printf("%d %d %d %d\n", i, --i, i, i--); } 输出是“3 ...
- Bet(The 2016 ACM-ICPC Asia China-Final Contest 思路题)
题目: The Codejamon game is on fire! Fans across the world are predicting and betting on which team wi ...
- slf4j-api、slf4j-log4j12、log4j的关系
在网上找到一篇关于这三个jar包的关系的博客,讲的很好,所以就转载了: https://blog.csdn.net/tengdazhang770960436/article/details/18006 ...
- gitlab root 账号 忘记密码如何重置
shell>cd /home/git/gitlabshell> su gitshell>bundle exec rails console productionirb(main):0 ...
- sectional data interpolation in Tecplot
$!Varset |NumLoop|= $!Loop |NumLoop| $!Varset |num|=(|Loop|*+) $!RotateData ZoneList = [] Angle = |n ...