Share via


XmlPoke task

Sets values as specified by an XPath query into an XML file.

Parameters

The following table describes the parameters of the XmlPoke task.

Parameter Description
Namespaces Optional String parameter.

Specifies the namespaces for XPath query prefixes. Namespaces is an XML snippet consisting of Namespace elements with attributes Prefix and Uri. The attribute Prefix specifies the prefix to associate with the namespace specified in Uri attribute. Do not use an empty Prefix.
Query Optional String parameter.

Specifies the XPath query.
Value Required ITaskItem parameter.

Specifies the value to be inserted into the specified path.
XmlInputPath Optional ITaskItem parameter.

Specifies the XML input as a file path.

Remarks

In addition to having the parameters that are listed in the table, this task inherits parameters from the TaskExtension class, which itself inherits from the Task class. For a list of these additional parameters and their descriptions, see TaskExtension base class.

Example

Here is a sample.xml to modify:

<Package xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
         xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest"
         xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10" >
<Identity Name="Sample.Product " Publisher="CN=1234" Version="1.0.0.0" />
<mp:PhoneIdentity PhoneProductId="456" PhonePublisherId="0" />
</Package>

In this example, if you want to modify /Package/mp:PhoneIdentity/PhoneProductId, then use

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <Namespace>
        <Namespace Prefix="dn" Uri="http://schemas.microsoft.com/appx/manifest/foundation/windows10" />
        <Namespace Prefix="mp" Uri="http://schemas.microsoft.com/appx/2014/phone/manifest" />
        <Namespace Prefix="uap" Uri="http://schemas.microsoft.com/appx/manifest/uap/windows10" />
    </Namespace>
</PropertyGroup>

<Target Name="Poke">
  <XmlPoke
    XmlInputPath="Sample.xml"
    Value="MyId"
    Query="/dn:Package/mp:PhoneIdentity/@PhoneProductId"
    Namespaces="$(Namespace)"/>
</Target>
</Project>

dn is here used as an artificial namespace prefix for default namespace.

See also