> For the complete documentation index, see [llms.txt](https://docs.bindplane.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.bindplane.com/integrations/processors/insert-xml-elements.md).

# Insert XML Elements

Inserts an XML fragment at an XPath location inside an XML string. A common use is back-filling empty elements with a placeholder so they survive a later parse. The output is the modified XML string.

### Supported Telemetry Types

| Logs | Metrics | Traces |
| ---- | ------- | ------ |
| ✓    | ✓       | ✓      |

Choose Telemetry Type picks one signal per processor instance. Add another instance to handle a second signal.

### Configuration

#### Basic Configuration

<figure><img src="/files/UHwJ69zgZwozcqWYAFPm" alt="Bindplane docs - Insert XML Elements - image 1"><figcaption></figcaption></figure>

**What to insert, and where**

| Parameter             | Type               | Required | Default   | Description                                                                                                       |
| --------------------- | ------------------ | -------- | --------- | ----------------------------------------------------------------------------------------------------------------- |
| Choose Telemetry Type | Telemetry Selector | Yes      | Logs      | The signal this instance runs on: Logs, Metrics, or Traces (one at a time).                                       |
| XPath                 | String             | Yes      | —         | The XPath selecting the element(s) to insert into. Applies to all selected telemetry types.                       |
| XML To Insert         | String             | Yes      | —         | The XML fragment to insert at the XPath, for example `<value>-</value>`. Applies to all selected telemetry types. |
| Condition             | OTTL Condition     | No       | *(empty)* | Insert only into records that match. Empty runs on every record.                                                  |

**Source and target fields**

| Parameter         | Type                                    | Required | Default   | Description                                                                                                                      |
| ----------------- | --------------------------------------- | -------- | --------- | -------------------------------------------------------------------------------------------------------------------------------- |
| Source Field Type | Enum: Resource, Attribute, Body, Custom | Yes      | Attribute | Where the XML string is read from. **Body is logs-only.** Custom takes any OTTL path.                                            |
| Source Field      | OTTL Field                              | Yes \*   | —         | The field holding the XML. Bracket notation for nested fields. For a Body source, leave empty to use the whole body.             |
| Target Field Type | Enum: Resource, Attribute, Body, Custom | Yes      | Attribute | Where the modified XML is written. **Body is logs-only.**                                                                        |
| Target Field      | OTTL Field                              | Yes \*   | —         | Destination for the modified XML. Point it at the source to edit in place. For a Body target, leave empty to use the whole body. |

\* The **Body** field type is the exception: it's optional, and leaving it empty targets the entire body.

**Body is available for Logs only.** For Metrics and Traces, the field type options are Resource, Attribute, and Custom.

### Examples

#### Back-fill empty elements before a parse

<figure><img src="/files/jFx6nr1mUzssZ20lVLbK" alt="Bindplane docs - Insert XML Elements - image 2"><figcaption></figcaption></figure>

#### XPath with a quoted predicate

<figure><img src="/files/vfOTZqAmUojkDnifGcuj" alt="Bindplane docs - Insert XML Elements - image 3"><figcaption></figcaption></figure>

XPath predicates and inserted fragments with quotes are entered as-is; embedded quotes are escaped safely when the config is generated.

### Configuration Tips

* Use this ahead of **Parse Simplified XML** to protect empty elements, which the parser would otherwise drop.

### Troubleshooting

#### Nothing gets inserted

Symptoms: the document is unchanged after the processor runs.

Solutions:

1. Verify the XPath matches at least one node in the source document.
2. Confirm the XML To Insert fragment is well-formed (balanced tags), and that the Condition evaluates true.

### Standalone Processor

```yaml
apiVersion: bindplane.observiq.com/v1
kind: Processor
metadata:
  name: insert-xml-elements
spec:
  type: xml_insert_elements
  parameters:
    - name: telemetry_types
      value: Logs
    - name: log_condition
      value: not IsMap(body)
    - name: xpath
      value: //Data[not(text())]
    - name: xml_value
      value: <value>-</value>
    - name: log_source_field_type
      value: Body
    - name: log_body_source_field
      value: ""
    - name: log_target_field_type
      value: Body
    - name: log_body_target_field
      value: ""
```

### Related Resources

* [InsertXML — OTTL function reference](https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/pkg/ottl/ottlfuncs/README.md#insertxml)

### Bindplane Resources

These XML and slice processors are designed to work together. Chain them to normalize, parse, and reshape XML end to end:

* [Convert XML Attributes To Elements](/integrations/processors/convert-xml-attributes-to-elements.md)
* [Convert XML Text To Elements](/integrations/processors/convert-xml-text-to-elements.md)
* [Parse Simplified XML](/integrations/processors/parse-simplified-xml.md)
* [Slice to Map](/integrations/processors/slice-to-map.md)
* [Get XML](/integrations/processors/get-xml.md)
* [Remove XML](/integrations/processors/remove-xml.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.bindplane.com/integrations/processors/insert-xml-elements.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
