【问题标题】:Applying an XDT transform to an XML complex type将 XDT 转换应用于 XML 复杂类型
【发布时间】:2020-11-04 02:27:00
【问题描述】:

我有一个部署到多个环境的 Service Fabric 应用程序,每个环境都由一个复杂类型的 Application xml 元素定义。在这个 Application 元素中是一个参数列表,我想对这些参数应用 XDT 转换。

目标 xml 看起来像:

<?xml version="1.0" encoding="utf-8"?>
<Application xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Name="fabric:/SimFabric" xmlns="http://schemas.microsoft.com/2011/01/fabric">
  <Parameters>
    <Parameter Name="Parameter1" Value="" key="key1"/>
    <Parameter Name="Parameter2" Value="" key="key2"/>
  </Parameters>
</Application>

我要粘贴的 Web.*.config 采用以下形式:

<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <configSections>
    <section name="configBuilders" type="System.Configuration.ConfigurationBuildersSection, System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" restartOnExternalChanges="false" requirePermission="false" />
  </configSections>
  <appSettings>
    <add xdt:Transform="Replace" xdt:Locator="Match(key)" key="key1" value="value1" />
    <add xdt:Transform="Replace" xdt:Locator="Match(key)" key="key2" value="value2" />
  </appSettings>
</configuration>

XDT 转换可以用来将第二个文件中的值放在第一个文件中吗?

【问题讨论】:

    标签: xml azure-service-fabric


    【解决方案1】:

    XDT 转换适用于每个 XML 文件。 你可以测试这个here

    来源:

    <Application xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
            Name="fabric:/SimFabric" xmlns="http://schemas.microsoft.com/2011/01/fabric">
              <Parameters>
                <Parameter Name="Parameter1" Value="" />
                <Parameter Name="Parameter2" Value="" />
              </Parameters>
    </Application>
    

    XDT 变换:

    <Application xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Name="fabric:/SimFabric"  xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform" xmlns="http://schemas.microsoft.com/2011/01/fabric">
     
      <Parameters>
        <Parameter xdt:Transform="Replace" xdt:Locator="Match(Name)" Name="Parameter1" Value="Value1" />
        <Parameter xdt:Transform="Replace" xdt:Locator="Match(Name)" Name="Parameter2" Value="Value2" />
      </Parameters>
    
    </Application>
    

    结果:

    <Application xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Name="fabric:/SimFabric" xmlns="http://schemas.microsoft.com/2011/01/fabric">
      <Parameters>
        <Parameter Name="Parameter1" Value="Value1" />
        <Parameter Name="Parameter2" Value="Value2" />
      </Parameters>
    </Application>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-09-08
      • 1970-01-01
      • 2012-03-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多