2012-04-28 121 views
4

如何選擇註釋或使用Web.config轉換插入註釋?Web.Config轉換xml註釋

無處可以找到關於此的任何信息。

我試圖做之一: 1)在Web.config現有註釋前插入一塊XML(<serviceAuthorization impersonateCallerForAllOperations="true"/>)的

OR

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]"/> 

我已經嘗試了其他幾個,但你明白了。預覽變換時我只是遇到了一個錯誤。

我似乎也無法找到關於如何插入評論的任何信息。我錯過了什麼嗎?

回答

2

我相信轉換僅限於對元素或屬性進行操作。至少,xdt:Transform上的documentation都沒有提及可用於添加評論的任何內容。

至於定位,那裏似乎是爲軸線一些支持,我可以使用以下命令:

<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> 

<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> 

以下操作時

正如你所看到的,abov e使用父軸來匹配要變換的元素。