从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的更多相关文章

  1. Create a custom configSection in web.config or app.config file

    config file: <?xml version="1.0" encoding="utf-8" ?> <configuration> ...

  2. Modifying namespace in XML document programmatically

    Modifying namespace in XML document programmatically static XElement stripNS(XElement root) { return ...

  3. MVC模式下unity配置,报错“No connection string named '**Context' could be found in the application config file”

     写在前面: 第一次配置时好好的,后来第二次改到MVC模式,把依赖注入写成字典的单例模式时,由于新建的ORM(数据库映射模型EF),怎么弄都不用,一直报错"No connection str ...

  4. Camel routes in Spring config file

    The normal spring bean definition configuration file, the xsi:schemaLocation only has two: beans and ...

  5. The web.config file for this project is missing the required DirectRequestModule.

    The web.config file for this project is missing the required DirectRequestModule.   将应用程序集的模式由集成改为经典 ...

  6. Can not find connection pool config file

    暂时未解决 checkActivation=====================true Can Not Parse ConnectionCfg! 2019/10/12-11:23:38 > ...

  7. [笔记]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 ...

  8. error in config file "/etc/rabbitmq/rabbitmq.config"

    记录一次RabbitMQ配置文件配置错误 error信息: dill@ubuntu-vm:/usr/share/doc/rabbitmq-server$ sudo /usr/lib/rabbitmq/ ...

  9. .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 ...

随机推荐

  1. jmeter接口测试小结

    摘自:http://www.cnblogs.com/houzhizhe/p/6839736.html JMeter做http接口压力测试 测前准备 用JMeter做接口的压测非常方便,在压测之前我们需 ...

  2. java虚拟机(六)--垃圾收集器和内存分配策略

    目前没有完美的收集器,不同的厂商.版本的虚拟机提供的垃圾收集器会有很大的差别,用户根据自己应用特点和要求组合出各个年代所使用 的收集器.基于jdk1.7Update14之后的虚拟机. HotSpot的 ...

  3. Could not resolve type alias 'map '. Cause: java.lang.ClassNotFoundException: Cannot find class: map

    把resultType改为resultMap, 把parameterType改为parameterMap,重新发布并运行.

  4. 用Docker构建Tomcat镜像

    构建tomcat镜像 创建工作目录 [root@elk-node2 tomcat]# mkdir tomcat [root@elk-node2 tomcat]# cd tomcat [root@elk ...

  5. 【原】Mysql常用语句

    1.修改编码方式为UTF-8 ALTER   TABLE   表名  CHANGE  列名  新列名  VARCHAR(255)    CHARACTER  SET  utf8  COLLATE    ...

  6. P1616 疯狂的采药(洛谷,动态规划递推,完全背包)

    先上题目链接:P1616 疯狂的采药 然后放AC代码: #include<bits/stdc++.h> #define ll long long using namespace std; ...

  7. Java:冒泡排序 | 二分查找

    2018-10-29 20:16:46 冒泡排序 例子(对数字排序): 假设有这样一组数字:32, 8, 128, 2, 64 现在对其进行冒泡排序(*表示下次比较的开始数字): 32>8? t ...

  8. buf.readUInt8()

    buf.readUInt8(offset[, noAssert]) offset {Number} 0 <= offset <= buf.length - 1 noAssert {Bool ...

  9. 九度oj 题目1066:字符串排序

    题目1066:字符串排序 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:6487 解决:2670 题目描述: 输入一个长度不超过20的字符串,对所输入的字符串,按照ASCII码的大小从小到 ...

  10. hrbust oj 1536 Leonardo's Notebook 置换群问题

    题目大意: 给出一个A~Z的置换G,问能否找到一个A~Z的置换G' 能够用来表示为 G = G'*G' 由定理: 任意一个长为 L 的置换的k次幂,都会把自己的每一个循环节分裂成gcd(L, K)份, ...