首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将XDT转换应用于XML复杂类型

将XDT转换应用于XML复杂类型
EN

Stack Overflow用户
提问于 2020-07-15 01:12:40
回答 1查看 47关注 0票数 0

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

目标xml如下所示:

代码语言:javascript
复制
<?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采用以下形式:

代码语言:javascript
复制
<?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转换将第二个文件中的值放在第一个文件中?

EN

回答 1

Stack Overflow用户

发布于 2020-07-15 14:29:19

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

来源:

代码语言:javascript
复制
<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变换:

代码语言:javascript
复制
<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>

结果:

代码语言:javascript
复制
<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>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62900473

复制
相关文章

相似问题

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