简体   繁体   中英

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. While I can add a new empty Item node, I can't select that node itself to add the required name subnode. I've tried using:

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

After creating the new Item node, but WiX fails to find it.

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() . XmlFile lets you set the language. Looks like an oversight on XmlConfig .

In the end I had to hard-code the various numbered s and use Sequence numbers to make sure the order is correct:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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