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); }
作者:Chuck Lu GitHub |
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· .NET Core GC计划阶段(plan_phase)底层原理浅谈
· .NET开发智能桌面机器人:用.NET IoT库编写驱动控制两个屏幕
· 用纯.NET开发并制作一个智能桌面机器人:从.NET IoT入门开始
· 一个超经典 WinForm,WPF 卡死问题的终极反思
· ASP.NET Core - 日志记录系统(二)
· 支付宝事故这事儿,凭什么又是程序员背锅?有没有可能是这样的...
· 在线客服系统 QPS 突破 240/秒,连接数突破 4000,日请求数接近1000万次,.NET 多
· C# 开发工具Visual Studio 介绍
· 在 Windows 10 上实现免密码 SSH 登录
· C#中如何使用异步编程