从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. 梦想CAD控件 2019.01.20更新

    下载地址:http://www.mxdraw.com/ndetail_10120.html1. 修改CAD不等比例块保存问题2. 修改CAD捕捉时,Z值对捕捉不准的影响3. 修改图片对象选择后,自动跑 ...

  2. 15Microsoft SQL Server 数据库维护

    Microsoft SQL Server 数据库维护 2.6.1数据库联机与脱机 --联机:该状态为数据库正常状态,也就是我们常看到的数据库的状态,该状态下的数据库处于可操作状态,可以对数据库进行任何 ...

  3. [angular1.6]Error: "transition superseded" ui-router 在angular1.6 报错误问题解决

    在angular1.6版本里,使用ui-router如果报这个错误,可以将ui-router升级到最近版本即可.ui-router version v0.4.2

  4. 洛谷——P1168 中位数

    P1168 中位数 题目描述 给出一个长度为NN的非负整数序列$A_i$​,对于所有1 ≤ k ≤ (N + 1),输出$A_1, A_3, …, A_{2k - 1}A1​,A3​,…,A2k−1​ ...

  5. unbuntu 安装软件

    下载ubutun镜像---------------------用win32diskimager将镜像文件写入u盘,使用u盘启动安装系统. 安装软件--------------------- 0,基本工 ...

  6. power coefficient calculation -- post processing

    input: unscaled moment of one bladeoutput: power coefficient of a 3-blades wind/tidal turbine matlab ...

  7. 阻塞套接字返回EAGAIN

    今天用NDK写了一个通信程序,发现阻塞SOKCET 读写的时候返回了EAGAIN.NDK下PERROR输出为Try Again.查了半天头文件 在网上找到了原因.在此纪录.网址为http://blog ...

  8. JUnit 深入

    Fixture 何谓 Fixture ?它是指在执行一个或者多个测试方法时需要的一系列公共资源或者数据,例如测试环境,测试数据等等.在编写单元测试的过程中,您会发现在大部分的测试方法在进行真正的测试之 ...

  9. lombok 插件安装

    1. 下载地址: https://plugins.jetbrains.com/plugin/6317-lombok-plugin 2. 选择从本地安装.

  10. Truck History(卡车历史)

    Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 26547   Accepted: 10300 Description Adv ...