Skip to content

How to manipulate XML with SIF

Ro Se edited this page May 20, 2018 · 1 revision

Sitecore Install Framework provides a task SetXml. With this task, we can add or update XML file content. On example a very popular Sitecore module - Web Forms For Marketers (WFFM), I will show you how to use SetXml task in practice. When you install WFFM module there is a manual step to perform after module installation - you have to add audio and video captcha handlers to the web.config.

The expected result in web.config is:

<add name="CaptchaImage" verb="*" path="CaptchaImage.axd" type="Sitecore.Form.Core.Pipeline.RequestProcessor.CaptchaResolver, Sitecore.Forms.Core" />
<add name="CaptchaAudio" verb="*" path="CaptchaAudio.axd" type="Sitecore.Form.Core.Pipeline.RequestProcessor.CaptchaResolver, Sitecore.Forms.Core" />

With the 'SetXml' task you can quickly achieve this, add the following task to module installation JSON.

How to install Sitecore modules and updates is described Option 1 or Option 2.

Task for add image captcha:

    "AddImageCaptcha": {
      "Type": "SetXml",
      "Params": {
        "FilePath": "[joinpath(variable('Site.WebsiteFolder'), 'Web.config')]",
        "XPath": "//configuration/system.webServer/handlers",
        "Element": "add",
        "Attributes": [
          {
            "name": "CaptchaImage",
            "verb": "*",
            "path": "CaptchaImage.axd",
            "type": "Sitecore.Form.Core.Pipeline.RequestProcessor.CaptchaResolver, Sitecore.Forms.Core"
          }
        ]
      }
    }