【问题标题】:Web.Config Transform xml commentsWeb.Config 转换 xml 注释
【发布时间】:2012-04-28 00:58:56
【问题描述】:

如何使用 Web.config 转换选择评论或插入评论?

我在任何地方都找不到这方面的任何信息。

我正在尝试执行以下任一操作: 1) 在 Web.config 中的现有注释前插入一段 xml (<serviceAuthorization impersonateCallerForAllOperations="true"/>)

2) 在一组兄弟的末尾插入注释和 xml:

据我所知,Web.config 转换不支持 xPath 轴,我尝试了其中的一些来尝试在第一条评论之前插入一个节点:

<serviceAuthorization impersonateCallerForAllOperations="true" xdt:Transform="InsertBefore(/configuration/system.serviceModel/behaviors/serviceBehaviors/behavior[@name='behaviorOne']/serviceMetadata/preceding::comment()[1])"/>

<serviceAuthorization impersonateCallerForAllOperations="true" xdt:Transform="InsertBefore(/configuration/system.serviceModel/behaviors/serviceBehaviors/behavior[@name='behaviorOne']/child::node()[1]"/>

我尝试了其他几个,但你明白了。我只是在预览转换时遇到错误。

我似乎也找不到有关如何插入评论的任何信息。我错过了什么吗?

【问题讨论】:

    标签: xpath web-config transform xdt-transform


    【解决方案1】:

    我相信转换仅限于对元素或属性进行操作。至少,xdt:Transform 上的documentation 中没有一个提到任何可用于添加评论的内容。

    至于定位器,似乎确实一些支持轴,因为我能够使用以下内容:

    <spring >
    <objects xmlns="http://www.springframework.net">
      <object >
        <constructor-arg index="0" type="System.Uri" value="https://example.com/test" xdt:Locator="Condition(../@name='requestConfig' and @index='0')" xdt:Transform="SetAttributes(value)"/>
      </object>
    </objects>
    

    在以下操作时:

    <spring >
    <objects xmlns="http://www.springframework.net">
        <object name="requestConfig" type="Example.Namespace.RequestConfig, Example" singleton ="true">
            <constructor-arg index="0" type="System.Uri" value="https://example.com/production"/>
            <constructor-arg index="1" value="45000"/>
        </object>
    </objects>
    

    如您所见,上面使用父轴来匹配要转换的元素。

    【讨论】:

      【解决方案2】:

      聚会晚了,但对于那些谷歌搜索,我发现了一些解决方法 - 如果您插入一个节点,它会在该节点内插入任何 cmets,显然您需要先将其删除。即:

        <customErrors xdt:Transform="Remove" />
        <customErrors mode="On" defaultRedirect="Hub/Error" xdt:Transform="Insert">
            <!-- comment -->          
        </customErrors>
      

      缺点是它会破坏子节点,但我尽量将评论放低以减轻损害。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2019-08-03
        • 2014-03-22
        • 1970-01-01
        • 2011-07-07
        • 2018-10-09
        • 1970-01-01
        • 2014-10-02
        相关资源
        最近更新 更多