从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. TypeError: 'TestCase' object is not iterable

    这个异常呢其实是因为我对list没有足够熟悉 我一开始很疑惑,明明已经正确返回testcase对象了呀,为啥会报TypeError: 'TestCase' object is not iterable ...

  2. Xamarin.Forms android实现沉浸式

    在android项目里,这样设置 using System; using Android.App; using Android.Content.PM; using Android.Runtime; u ...

  3. C/C++野指针

    野指针: 野指针不同于空指针,空指针是指一个指针的值为null,而野指针的值并不为null,野指针会指向一段实际的内存,只是它指向哪里我们并不知情,或者是它所指向的内存空间已经被释放,所以在实际使用的 ...

  4. Jmeter - 获取返回结果中的字段值

    Jmeter测试场景:一个web系统,需要先发送登录请求,获取到登录Token之后,后续每次请求都需要在请求头中附带Token才有权限操作.现在需要在Jmeter中自动获取每次登录请求返回的Token ...

  5. OS X中crt中文乱码

    SecureCRT中显示乱码的话,可以去设置为UTF-8编码: Session Options->Terminal->Appearance->Character Encoding,设 ...

  6. BZOJ 4919 [Lydsy1706月赛]大根堆 (SRM08 T3)

    [题解] 求一个序列的LIS有一个二分做法是这样的:f[i]表示长度为i的上升序列中最后一个数最小可以是多少,每次二分大于等于当前数字x的f[j],把f[j]修改为x:如果找不到这样的f[j],那就把 ...

  7. 洛谷 4246 BZOJ 1018 [SHOI2008]堵塞的交通

    [题解] 原来线段树还可以这么玩.. 我们用线段树维护连通性.对于一个矩形,我们用4个标记维护4个点的联通情况,再用两个标记维护右边两个点与它们右边的与它们在同一行的点的联通情况. 画图表示,就是 另 ...

  8. Delphi语法

    类与对象 从用户角度考虑,用户并不需要了解面向对象编程的知识,就可编写Delphi应用程序.当用户在建立新窗体.添加新组件以及处理事件时,大部分相关代码会由Delphi自动产生.但是,知道语言及其细节 ...

  9. Leetcode 135.分糖果

    分发糖果 老师想给孩子们分发糖果,有 N 个孩子站成了一条直线,老师会根据每个孩子的表现,预先给他们评分. 你需要按照以下要求,帮助老师给这些孩子分发糖果: 每个孩子至少分配到 1 个糖果. 相邻的孩 ...

  10. 数论结论 nefu 702

    Given a prime p (p<108),you are to find min{x2+y2},where x and y belongs to positive integer, so ...