首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SlowCheetah变换忽略多个条件

SlowCheetah变换忽略多个条件
EN

Stack Overflow用户
提问于 2014-06-09 17:57:44
回答 1查看 897关注 0票数 1

我有一个WCF配置文件,我正在尝试用SlowCheetah进行转换。对于开发用途,我们希望包括MEX端点,但是当我们发布产品时,除了一个以外,所有服务上都应该删除这些端点。应该为其保留的服务器具有以下端点:

代码语言:javascript
复制
<endpoint address="MEX" 
          binding="mexHttpBinding" 
          contract="IMetadataExchange" />

应予删除的部分如下:

代码语言:javascript
复制
    <endpoint address="net.tcp://computername:8001/WCFAttachmentService/MEX"
                        binding="netTcpBinding"
                        bindingConfiguration="UnsecureNetTcpBinding"
                        name="WCFAttachmentServiceMexEndpoint"
                        contract="IMetadataExchange" />

我正在使用的转换是:

代码语言:javascript
复制
<service>
    <endpoint xdt:Locator="Condition(contains(@address, 'MEX') and not(contains(@binding, 'mexHttpBinding')))" xdt:Transform="RemoveAll" />
</service>

但是,当我运行这个命令时,所有MEX端点都会从配置文件中删除,包括我希望保留的那个。我怎样才能使它正常工作呢?

EN

回答 1

Stack Overflow用户

发布于 2014-06-19 05:21:59

选择节点的Locator条件表达式似乎是正确的。如果只有在示例中张贴的两个端点,则该表达式将选择第二个端点。

根据文档Transform属性RemoveAll应该“删除所选的元素”。根据您发布的信息,它不能像预期的那样工作,因为第一个元素没有被选中,而且已经被删除。基于这个StackOverflow的答案,在我看来,问题在于Condition。我不确定这是否是一个bug (它的文档很少),但是您可以尝试一些替代的解决方案:

1)使用XPath代替Condition。作为XPath表达式的结果应用于配置文件的有效Condition表达式是:

代码语言:javascript
复制
/services/service/endpoint[contains(@address, 'MEX') and not(contains(@binding, 'mexHttpBinding'))]

您还应该使用XPath属性而不是Condition获得相同的结果。

代码语言:javascript
复制
<endpoint xdt:Locator="XPath(/services/service/endpoint[contains(@address, 'MEX') 
                             and not(contains(@binding, 'mexHttpBinding'))])" xdt:Transform="RemoveAll" />

2)使用Match并测试属性(如binding )。这是一个简单的测试,并将是国际海事组织进行比赛的首选方式。可以通过binding属性选择要删除的节点。

代码语言:javascript
复制
<endpoint binding="netTcpBinding" xdt:Locator="Match(binding)" xdt:Transform="RemoveAll" />

3)如果您有许多不同的绑定,并且只想消除那些不是XPath的绑定,则使用Match代替mexHttpBinding

代码语言:javascript
复制
<endpoint xdt:Locator="XPath(/services/service/endpoint[not(@binding='mexHttpBinding'))" xdt:Transform="RemoveAll" />

4)最后,可以尝试在Condition()Match()中使用几个单独的语句来单独选择要删除的<endpoint>元素,并使用xdt:Transform="Remove"而不是RemoveAll

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24126008

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档