gpt4 book ai didi

xml - 使用 XPath 在 WIX 中删除带有 XmlConfig 扩展名的 XML 元素

转载 作者:数据小太阳 更新时间:2023-10-29 02:21:59 27 4
gpt4 key购买 nike

我正在尝试使用 XmlFile 扩展来删除 XML 文件中的条目,准确地说是这个:< Element name="Somename"attribute2="whatever"provider-name="whatever2"type="DotNet">

这是我的 XML 文件

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Elements>
<Element name="Somename" attribute2="whatever" provider-name="whatever2" type="DotNet"></Element>
<Element name="Somename2" attribute2="whatever" provider-name="whatever2" type="DotNet"></Element>
</Elements>

这是我的 Wix 代码

<Feature Id='Config' Level='1'>
<Component KeyPath="yes" Id="UpdateConfig" Guid="{xxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}" Directory="MyCommonAppDataFolders">
<util:XmlConfig Action="delete" Id="RemoveAnElement" Node="element" File="path\to\my\file.xml" VerifyPath='/Elements/Element[\[]@name=\"Somename"[\]]' ElementPath="/Elements/Element" Sequence="1" />
</Component>
<Condition Level="1">FILEEXISTS</Condition>
</Feature>

当我运行安装程序时,它会重写 file.xml,但它看起来是一样的。它不会删除 -> < Element name="Somename"attribute2="whatever"provider-name="whatever2"type="DotNet">

我做错了什么?我在构建时没有收到任何错误,也许我的 xpath 有误?

最佳答案

  1. 要删除 XML 元素,您需要使用 XMLConfig Element

  2. XMLFIile Element用于更新/删除元素内的属性:

    deleteValue - Deletes a value from the element specified in the ElementPath. If Name is specified, the attribute with that name is deleted. If Name is not specified, the text value of the element specified in the ElementPath is deleted. The Value attribute is ignored if deleteValue is the action specified.

由于您没有提及“名称”属性,它正在尝试删除文本值。您在 ELEMENT 中没有文本值,因此即使在编辑后您的文件也保持不变。

更新:使用 WIX 脚本更新了答案

<util:XmlConfig Id='SetXMlfiletest'
File='[#filename]'
Action='delete'
Node='element'
ElementPath="/Elements"
On='install'
PreserveModifiedDate='yes'
VerifyPath="/Elements/Element[\[]@name='Somename'[\]]"
Sequence="1" />

在上面的脚本中,您需要使用您的 xml 文件的 ID 更新“#filename”。

希望这对您有所帮助!

关于xml - 使用 XPath 在 WIX 中删除带有 XmlConfig 扩展名的 XML 元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22665526/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com