---
title: "Configuration patch file examples"
slug: "configuration-patch-file-examples"
abstract: "Examples of how to write patch files that add or change server configuration settings."
---
# Configuration patch file examples

The following examples of patch syntax illustrate how patching affects configuration. All examples show the original configuration, then the patch files, and finally the configuration after the patch files have been merged with the `Sitecore.config` file.

The examples illustrate:

- [Merging configurations](https://doc.sitecore.com/xp/en/developers/101/platform-administration-and-architecture/configuration-patch-file-examples.html#UUID-8c9bd265-ffc6-f7e5-5fc5-0ee0228792c6_id__Merge_configurations "Merging configurations")
- [Inserting an element before a specific element](https://doc.sitecore.com/xp/en/developers/101/platform-administration-and-architecture/configuration-patch-file-examples.html#UUID-8c9bd265-ffc6-f7e5-5fc5-0ee0228792c6_id__Override_a_configuration "Inserting an element before a specific element")
- [Inserting an element after a specific element](https://doc.sitecore.com/xp/en/developers/101/platform-administration-and-architecture/configuration-patch-file-examples.html#UUID-8c9bd265-ffc6-f7e5-5fc5-0ee0228792c6_id__Insert_an_element_2 "Inserting an element after a specific element")
- [Adding or updating an attribute](https://doc.sitecore.com/xp/en/developers/101/platform-administration-and-architecture/configuration-patch-file-examples.html#UUID-8c9bd265-ffc6-f7e5-5fc5-0ee0228792c6_id__Add_or_update "Adding or updating an attribute")
- [Deleting an element](https://doc.sitecore.com/xp/en/developers/101/platform-administration-and-architecture/configuration-patch-file-examples.html#UUID-8c9bd265-ffc6-f7e5-5fc5-0ee0228792c6_id__Deleting_an_element "Deleting an element")
- [Replacing the value of an element](https://doc.sitecore.com/xp/en/developers/101/platform-administration-and-architecture/configuration-patch-file-examples.html#UUID-8c9bd265-ffc6-f7e5-5fc5-0ee0228792c6_id__Replacing_the_value "Replacing the value of an element")

To customize your configuration, you can use these examples of patch syntax to help you [add or change configuration settings](https://doc.sitecore.com/xp/en/developers/101/platform-administration-and-architecture/use-a-patch-file-to-customize-the-sitecore-configuration.html "Use a patch file to customize the Sitecore configuration").

To use the `patch` and `set` namespaces, declare them at the beginning of the patch file as part of the `<configuration>` setting:

```xml
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/"
xmlns:set="http://www.sitecore.net/xmlconfig/set/">
    <sitecore>
        . . . . .
    </sitecore>
</configuration>

```

## Merging configurations

Configurations from different patch files are merged in the order the patch files are processed.

```xml
<!-- Sitecore.config -->
<settings>
  <setting name="name" value="Aaron" />
</settings>
<!-- /App_Config/Include/file1.config -->
<settings>
  <setting name="city" value="New York" />
</settings>
<!-- /App_Config/Include/file2.config -->
<settings>
  <setting name="country" value="USA" />
</settings>

```

The configuration used at runtime is:

```xml
<settings>
  <setting name="name" value="Aaron" />
  <setting name="city" value="New York" />
  <setting name="country" value="USA" />
</settings>

```

## Inserting an element before a specific element

You can insert a configuration element before a specific element. This example adds a processor before the processor with the `test2` type, regardless of the position of `test2` in the configuration:

```xml
<!-- Sitecore.config -->
<test>
  <processor type="test1" />
  <processor type="test2" />
  <processor type="test3" />
</test>
<!-- Patch file -->
<test>
  <processor type="testA" patch:before = "processor[@type='test2']"/>
</test>

```

The configuration used at runtime is:

```xml
<test>
  <processor type="test1" />
  <processor type="testA" />
  <processor type="test2" />
  <processor type="test3" />
</test>

```

## Inserting an element after a specific element

You can insert a configuration element after a specific existing element. This example inserts a processor after the processor with the `test2` type, regardless of the position of `test2` in the configuration:

```xml
<!-- Sitecore.config -->
<test>
  <processor type="test1" />
  <processor type="test2" />
  <processor type="test3" />
</test>
<!-- Patch file -->
<test>
  <processor type="testA" patch:after = "processor[@type='test2']"/>
</test>

```

The configuration used at runtime is:

```xml
<test>
  <processor type="test1" />
  <processor type="test2" />
  <processor type="testA" />
  <processor type="test3" />
</test>

```

## Adding or updating an attribute

You can add a new attribute or update the value of an existing attribute. If the attribute already exists, its existing value is replaced by the value from the patch file. If the attribute does not already exist in `mysite`, it is added to `mysite`. You can use either the `patch` namespace or the `set` namespace to achieve this effect.

This example adds the `domainPath` attribute to the `mysite` site, sets it to `/home`, and changes the `virtualFolder` attribute to `/sitecore modules/web`:

```xml
<!-- Sitecore.config -->
<sites>
  <site name="mysite" virtualFolder="/"></site>
</sites>

```

This patch file uses the `patch` namespace to change the attributes:

```xml
<!-- Patch file -->
<sites>
    <site name="mysite" virtualFolder="/">
        <patch:attribute name="domainPath">/home</patch:attribute>
        <patch:attribute name="virtualFolder">/sitecore modules/web</patch:attribute>
    </site>
</sites>

```

This patch file uses the `set` namespace to achieve the same result:

```xml
<!-- Patch file -->
<sites>
    <site name="mysite" virtualFolder="/" set:domainPath="/home" set:virtualFolder="/sitecore modules/web"></site>
</sites>

```

The final result is the same for both patch files. The configuration used at runtime is:

```xml
<sites>
  <site name="mysite" domainPath="/home" virtualFolder="/sitecore modules/web"></site>
</sites>

```

## Deleting an element

You can delete a configuration element using `patch:delete`. Specify the `name` attribute for the element node in order to identify the element to remove.

> [!important]
> Take care when using `patch:delete` because it removes the specified element and all its attributes from the configuration at runtime.

For example, this is the given Sitecore config:

```xml
<!-- Sitecore config -->
<sitecore>
    <element name="a"/>
    <element name="b"/>
    <element name="c"/>
</sitecore>

```

The corresponding patch config deletes element "b":

```xml
<!-- Patch file -->
<sitecore>
    <element name="b">
        <patch:delete />
    </element>
</sitecore>

```

The configuration used at runtime is:

```xml
<sitecore>
    <element name="a"/>
    <element name="c"/>
</sitecore>

```

If the element doesn't have a name attribute, you can list the element to remove and all its attributes, and include the `patch:delete` element. For example, this is the configuration file:

```xml
<sitecore>
  <element type="example" value="foo" />
  <element type="example" value="bar" />
</sitecore>

```

And this is the corresponding patch file:

```xml
<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <element type="example" value="foo">
      <patch:delete />
    </element>
  </sitecore>
</configuration>

```

The resulting configuration at runtime is:

```xml
<sitecore>
  <element type="example" value="bar" />
</sitecore>

```

## Replacing the value of an element

Use the `patch:instead` attribute to specify that the selected element should be inserted instead of a sibling element. Unlike `patch:before` and `patch:after`, this attribute allows you to completely replace the original node or element.

The syntax is:

`<processor type="CustomC, CustomA" patch:instead="*[@type='Sc, Sc']" />`

```xml
<!-- Sitecore.config -->
<sitecore>
    <element name="a"/>
    <element name="b"/>
    <element name="c"/>
</sitecore>
<-- Patch file -->
<sitecore>
    <element name="d" patch:instead="*[@name='b']"/>
</sitecore>

```

The configuration used at runtime is:

```xml
<sitecore>
    <element name="a"/>
    <element name="d"/>
    <element name="c"/>
</sitecore>

```