How can I update a Sitecore XML patch file using SIF?

Sitecore Asked by MartinMace on February 20, 2021

I want to leverage SIF with the Set-Xml task to update the value in the datafolder.config patch file. But so far it seems I am not succeeding in finding the correct XPath due to the XML NS in the file.

I am using the following XPath expression:


For your reference, this is the datafolder.config file shipped with Sitecore 8.2 U7:

<configuration xmlns:patch="">
    <sc.variable name="dataFolder">
      <patch:attribute name="value">/data</patch:attribute>

Is it possible to set the value using SIF and an XPath expression? And if so, which XPath might do the trick? Any help is appreciated.

2 Answers

Okay, I got it working. The problem was with the inability of the SetXml SIF task to provide an XML NS.

So I created a custom task based on the SetXml task with an extra parameter to provide the namespace, the SIF configuration (in my case) then becomes as follows:

"SetDataFolder": {
      "Type": "SetXml",
      "Params": {
        "FilePath": "[joinpath(variable('Site.WebsiteFolder'), 'App_Config', 'Include', 'DataFolder.config')]",
        "XPath": "//configuration/sitecore/sc.variable[@name='dataFolder']/patch:attribute[@name='value']",
        "Namespace": [
            "patch": ""
        "Value": "[parameter('DataFolder')]"        

To accomplish this, just copy the complete SetXml task from the SIF library, make the necessary modifications to support the namespace in the Select-XML method, and include it in your module loading and be sure to register it using an overwrite of the out-of-the-box module using

Register-SitecoreInstallExtension -Command Invoke-SetXmlTaskEx -As SetXml -Type Task -Force

Hopefully this will help anyone else stumbling into the same problem until it hopefully becomes part of the official SIF version.

Correct answer by MartinMace on February 20, 2021

As Martine Said you either need to create Extension for SetXml to support namespaces, or in simple cases like DataFolder you can use some trick like this:

"CopyDataFolderConfig": {
        "Type": "Copy",
        "Params": {
            "Source": "[joinpath(variable('Site.PhysicalPath'), 'App_Config','Include','Examples','DataFolder.config.example')]",
            "Destination": "[joinpath(variable('Site.PhysicalPath'), 'App_Config','Include', 'DataFolder.config')]"
    "PatchDataFolder": {
        "Description": "Changing Data Folder.",
        "Type": "SetXml",
        "Params": {
            "FilePath": "[joinpath(variable('Site.PhysicalPath'), 'App_Config','Include', 'DataFolder.config')]",
            "XPath": "//configuration/sitecore/sc.variable[@name='dataFolder']/*",
            "Value": "[variable('Site.DataFolder')]"

using '*' as a selector in such cases is not generaly a good idea, but in this case it wont cause any problem.

Answered by Ghodrat Ashournia on February 20, 2021

Add your own answers!

Related Questions

This site cant be reached error while I am loading sitecore 8.2 client

2  Asked on December 30, 2021 by manideep-yechuri


Prevent sitecore from creating the the sitename#lang cookie

2  Asked on December 20, 2021 by manoj-sreekumar


Using serilog on Sitecore 9.0.1

1  Asked on December 13, 2021 by alecasciaro


How to identify configured tasks in visual studio

1  Asked on December 11, 2021 by jeyanth-praveenkumar


How to debug Sitecore Helix Feature using Visual Studio 2017?

2  Asked on December 7, 2021 by grilosape


Ask a Question

Get help from others!

© 2023 All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP