换句话说,在下面的 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/