visual-studio - 如何使用 XML-Document-Transform 从 web.config 中删除 Elmah 模块?

标签 visual-studio xpath xslt xdt-transform xml-document-transform

换句话说,在下面的 web.config xml 中,我想删除所有类型属性以“Elmah”开头的元素。

<httpModules>
  <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" />
  <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" />
  <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" />
</httpModules>

我尝试了几种基本变换的组合和结构,但有各种错误,
<add xdt:Locator="XPath([starts-with(@type,'Elmah.')" xdt:Transform="Remove"/>

在放弃并删除整个 httpModules 元素之前,因为不需要 XPath。

最佳答案

XPath 定位器需要一个完全限定的 XPath 位置,因此您的转换当前不匹配任何元素。如果您改用 Condition Locator(它需要一个相对 XPath),它应该匹配:

<add xdt:Locator="Condition(starts-with(@type,'Elmah.')" xdt:Transform="RemoveAll"/>

另请注意, xdt:Transform Remove 只会对第一个匹配的元素进行操作,因此您需要使用 RemoveAll 来实现您想要的。

summary在 msdn 上很好地涵盖了这一点。

关于visual-studio - 如何使用 XML-Document-Transform 从 web.config 中删除 Elmah 模块?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12166618/

相关文章:

c# - 如何在 Visual Studio 2015 中禁用 C# 6 支持?

r - 如何单击 javascript "link"?是我的 xpath 还是我的 relenium/selenium 用法?

html - xslt 允许在 concat 和 normalize-space 中使用参数

xml - 使用 XSLT 从嵌套的 XML 结构转换为扁平化的 XML 结构

c# - "There was an error running the selected code generator: ' 值 -1 超出了 [0,2147483647] 的可接受范围。参数名称:value '' "

c# - 如何更新此类/方法以改进代码指标

c++ - 如何创建一个最小的测试用例来展示/EHs 的成本?

java - Selenium xpath : Finding first table in the tables list

xml - 为什么XSLT不喜欢我的XPath查询?

java - SAXTransform 链中的第二个 XSLT 似乎没有执行任何操作