简体   繁体   English

使用WiX添加具有相似名称的XML节点

[英]Adding XML nodes with similar names using WiX

We have a configuration file of the form: 我们有以下形式的配置文件:

<Container>
    <Item>
        <name>Text</name>
    </Item>
    <Item>
        <name>MoreText</name>
    <Item>
</Container>

and want to add more Item/Name nodes using XMLFile or XMLConfig. 并希望使用XMLFile或XMLConfig添加更多的Item / Name节点。 While I can add a new empty Item node, I can't select that node itself to add the required name subnode. 虽然我可以添加一个新的空Item节点,但不能选择该节点本身来添加所需的名称子节点。 I've tried using: 我试过使用:

ElementPath="/Container/Item[\[]last()[\]]"

After creating the new Item node, but WiX fails to find it. 创建新的Item节点后,但是WiX找不到它。

Have I gone completely off the wall? 我已经完全离开了墙吗?

Just guessing but the problem may be that the default selection language. 只是猜测,但问题可能是默认选择语言。 IIRC, the old "XSLPattern" selection language is the default and does not support last() . IIRC,旧的“ XSLPattern”选择语言是默认语言,不支持last() XmlFile lets you set the language. XmlFile允许您设置语言。 Looks like an oversight on XmlConfig . 看起来像对XmlConfig

In the end I had to hard-code the various numbered s and use Sequence numbers to make sure the order is correct: 最后,我不得不对各种编号s进行硬编码,并使用序列号来确保顺序正确:

<util:XmlConfig Id="NewItem1" Action="create" File="[DIR]\Item.config" ElementPath="/Container" Name="Item" Node="element" On="install" Sequence="50" />
<util:XmlConfig Id="NewName1" Action="create" File="[DIR]\Item.config" ElementPath="/Container/Item[\[]2[\]]" Name="name" Value="MoreText1" Node="element" On="install" Sequence="51" />
<util:XmlConfig Id="CreatePRAlertEmailNode"  Action="create" File="[DIR]\Item.config" ElementPath="/Container" Name="Item" Node="element" On="install" Sequence="52" />
<util:XmlConfig Id="CreatePRAlertEmailName"  Action="create" File="[DIR]\Item.config" ElementPath="/Container/Item[\[]3[\]]" Name="name" Value="MoreText2"  Node="element" On="install" Sequence="53" />
<util:XmlConfig Id="CreatePRAlertRSSNode"    Action="create" File="[DIR]\Item.config" ElementPath="/Container" Name="Item" Node="element" On="install" Sequence="54" />
<util:XmlConfig Id="CreatePRAlertRSSName"    Action="create" File="[DIR]\Item.config" ElementPath="/Container/Item[\[]4[\]]" Name="name" Value="MoreText3"    Node="element" On="install" Sequence="55" />

It's not ideal and needs to changed if the endpoint changes, but it works for now. 这不是理想的,如果端点发生更改,则需要更改,但是它现在可以使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM