gpt4 book ai didi

xml - 使用 MSBuild.ExtensionPack.Xml.XmlFile UpdateElement 更新 XML 文件

转载 作者:行者123 更新时间:2023-12-03 16:27:36 26 4
gpt4 key购买 nike

我有一个 MSBUILD 项目文件,我正在尝试 checkout 一些 xml 文件并更新版本元素,但似乎无法让它为我的生活工作。这似乎应该是一个简单的解决方案,但我无法让它工作。我有一个简单的 xml 文件:

<?xml version="1.0" standalone="yes"?>
<DataSet>
<Profile>
<Product>ProductA</Product>
<Version>1.2.3.4</Version>
</Profile>
~
</DataSet>

我可以使用 xmlPeek 获取版本:
<XmlPeek XmlInputPath="c:\myProfile.xml"
Query="DataSet/Profile/Version[../Product = &quot;ProductA&quot;]/text()">
<Output TaskParameter="Result" ItemName="ProductVersion" />
</XmlPeek>

我没有运气使用 XmlPoke 更新版本,所以我从 XmlFile 的类页面尝试了 XmlFile 的 UpdateElement:

http://www.msbuildextensionpack.com/help/4.0.5.0/html/4009fe8c-73c1-154f-ee8c-e9fda7f5fd96.htm
  <MSBuild.ExtensionPack.Xml.XmlFile
TaskAction="UpdateElement"
File="c:\machine.config"
XPath="/configuration/configSections/section[@name='system.data']"
InnerText="NewValue"/>

我尝试了以下以及许多其他 XPath 版本,但都没有。
  <MSBuild.ExtensionPack.Xml.XmlFile
TaskAction="UpdateElement"
File="c:\myProfile.xml"
XPath="/DataSet/Profile/Version[@Product='ProductA']"
InnerText="5.6.7.8"
/>

我错过了什么?或者有人知道 xmlpoke 的正确 XPath

谢谢

最佳答案

在 XPath 中,@用于引用属性,如 @attribute_name .所以你尝试的 XPath 的一部分 Version[@Product='ProductA'] , 将寻找 Version具有 Product 的元素属性值等于“ProductA”,类似于以下内容(在您的 XML 中不存在):

<Version Product="ProductA"/>

获取 Version 的正确 XPath元素 Product名称如下:
/DataSet/Profile[Product='ProductA']/Version

这个特殊的部分 Profile[Product='ProductA'] , 过滤器 Profile具有子元素的元素 Product等于“产品A”。

关于xml - 使用 MSBuild.ExtensionPack.Xml.XmlFile UpdateElement 更新 XML 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37259357/

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