WiX XmlConfig:在 XmlConfig 中嵌套 XmlConfig 的目的 [英] WiX XmlConfig: Purpose for nesting XmlConfig in XmlConfig

查看:27
本文介绍了WiX XmlConfig:在 XmlConfig 中嵌套 XmlConfig 的目的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在另一个 XmlConfigXmlConfig 元素的目的和/或获得什么(除了增加创建/删除属性的可读性)> 元素?

我所指的示例(我使用的是 WiX 3.6):

What is the purpose and/or gain (other than increased readability for creating/deleting attributes) to nesting an XmlConfig element in another XmlConfig element?

Example of what I'm referring to (I'm using WiX 3.6):

<util:XmlConfig ...>
    <util:XmlConfig ... />
</util:XmlConfig>

推荐答案

简短的回答:嵌套 选项的唯一目的元素是能够以更具可读性的方式向/从新创建的元素添加/删除属性.所以,这基本上就是你的假设.

The short answer: the only purpose of the option to have nested <util:XmlConfig> elements is to be able to add/remove attributes to/from the newly created elements in a more readable way. So, this is basically what you assumed.

考虑以下初始 XML 文件:

Consider the following initial XML file:

<?xml version="1.0" encoding="utf-8"?>
<cars>
  <car name="ford" type="minivan"/>
  <car name="toyota" type="sedan"/>
  <motos>
    <moto name="honda" model="shadow" type="cruiser" />
  </motos>
</cars>

为了向其中添加另一个 ,可以使用以下 WiX 代码段:

In order to add another <moto> to it, the following WiX snippet can be used:

<util:XmlConfig Id="elem1" Action="create" ElementPath="cars/motos" File="$(var.XmlFilePath)" Node="element" On="install" Name="moto">
  <util:XmlConfig Id="elem11" ElementId="elem1" Name="name" Value="yamaha" File="$(var.XmlFilePath)" />
  <util:XmlConfig Id="elem12" ElementId="elem1" Name="type" Value="chopper" File="$(var.XmlFilePath)" />
</util:XmlConfig>

结果,XML 文件最终如下:

As a result, the XML file ends up as follows:

<?xml version="1.0" encoding="utf-8"?>
<cars>
  <car name="ford" type="minivan"/>
  <car name="toyota" type="sedan"/>
  <motos>
    <moto name="honda" model="shadow" type="cruiser" />
    <moto name="yamaha" type="chopper" />
  </motos>
</cars>

这里需要注意的几件事:

Couple of things to note here:

  • 不能在内部 XmlConfig 元素中定义 Action 属性,这是合乎逻辑的 - 它与父元素之一相同
  • Node 属性也不能定义,因为只允许属性
  • 奇怪的是,您每次都必须指定 File 属性 - 这里似乎是一个设计问题
  • ElementId 属性应该指向您要向其添加属性的父元素,这也很奇怪,因为它也可以从嵌套代码中猜出"
  • the Action attribute can't be defined in inner XmlConfig elements, and that's logical - it is the same as the one of the parent element
  • the Node attribute can't be defined as well, because only attributes are allowed
  • the weird thing is that you have to specify File attribute each time - seems to be a design issue here
  • the ElementId attribute should point to the parent element you are adding the attributes to, and that's also strange as it could also be "guessed" from the nested code

无论如何,如果您确实想创建一个 XML 子树结构,最终在结果 XML 中作为嵌套元素的元素是由位于同一级别的 XmlConfig 元素构成的.因此,以下代码段:

Anyway, if you do want to create an XML subtree structure, the elements which end up as nested elements in resulting XML are made by XmlConfig elements placed on a same level. So, the following snippet:

<util:XmlConfig Id="elem1" Action="create" ElementPath="cars/motos" File="$(var.XmlFilePath)" Node="element" On="install" Name="moto" Sequence="1">
  <util:XmlConfig Id="elem11" ElementId="elem1" Name="name" Value="yamaha" File="$(var.XmlFilePath)" />
  <util:XmlConfig Id="elem12" ElementId="elem1" Name="type" Value="chopper" File="$(var.XmlFilePath)" />
</util:XmlConfig>
<util:XmlConfig Id="elem2" Action="create" ElementPath="cars/motos/moto[\[]@name='yamaha'[\]]" File="$(var.XmlFilePath)" Node="element" On="install" Name="extra" Sequence="2">
  <util:XmlConfig Id="elem21" ElementId="elem2" File="$(var.XmlFilePath)" Name="bags" Value="leather" />
</util:XmlConfig>

将按如下方式转换 XML:

will transform the XML as follows:

<?xml version="1.0" encoding="utf-8"?>
<cars>
  <car name="ford" type="minivan"/>
  <car name="toyota" type="sedan"/>
  <motos>
    <moto name="honda" model="shadow" type="cruiser"/>
    <moto name="yamaha" type="chopper">
      <extra bags="leather"/>
    </moto>
  </motos>
</cars>

注意以下几点:

  • XmlConfig 元素被放置在同一级别,尽管它们会在结果 XML 中产生嵌套元素
  • Sequence 属性很重要,以防您向元素添加属性或子元素,元素也正在创建
  • the XmlConfig elements are placed on the same level, although they result in a nested elements in the resulting XML
  • the Sequence attribute is important, in case you add an attribute or a child to the element, which is also being created

希望现在更有意义.很抱歉最初给出的错误答案.

Hope this makes more sense now. Sorry for the wrong answer given initially.

这篇关于WiX XmlConfig:在 XmlConfig 中嵌套 XmlConfig 的目的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆