Reputation: 172
I have an MSBUILD project file and I am trying to checkout some xml files and update a Version element and can't seem to get this to work for the life of me. This seems like it should be a simple solution but I cannot get it to work. I have a simple xml file:
<?xml version="1.0" standalone="yes"?>
<DataSet>
<Profile>
<Product>ProductA</Product>
<Version>1.2.3.4</Version>
</Profile>
~
</DataSet>
I can get the Version by using xmlPeek:
<XmlPeek XmlInputPath="c:\myProfile.xml"
Query="DataSet/Profile/Version[../Product = "ProductA"]/text()">
<Output TaskParameter="Result" ItemName="ProductVersion" />
</XmlPeek>
I had no luck using XmlPoke updating the Version so I tried XmlFile's UpdateElement from XmlFile's class page:
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"/>
I tried the follwing plus many other XPath versions to which none has worked.
<MSBuild.ExtensionPack.Xml.XmlFile
TaskAction="UpdateElement"
File="c:\myProfile.xml"
XPath="/DataSet/Profile/Version[@Product='ProductA']"
InnerText="5.6.7.8"
/>
What am I missing?
Or does anyone know the correct XPath for xmlpoke
Thanks
Upvotes: 2
Views: 713
Reputation: 89285
In XPath, @
is used to reference attribute like @attribute_name
. So part of your attempted XPath Version[@Product='ProductA']
, will look for Version
element that have Product
attribute value equals 'ProductA', something like the following (which doesn't exist in your XML) :
<Version Product="ProductA"/>
The correct XPath to get Version
element by Product
name would be as follow :
/DataSet/Profile[Product='ProductA']/Version
This particular part Profile[Product='ProductA']
, filters Profile
element that have child element Product
equals 'ProductA'.
Upvotes: 1