# XML parser, alter field

**URL:** <https://discuss.elastic.co/t/xml-parser-alter-field/269415>\
**Category:** Logstash\
**Created:** [April 7, 2021, 7:36am UTC](https://discuss.elastic.co/t/xml-parser-alter-field/269415 "2021-04-07T07:36:31Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Soren\_vdc](https://avatars.discourse-cdn.com/v4/letter/s/b4bc9f/32.png) [@Soren\_vdc](https://discuss.elastic.co/u/Soren_vdc)\
**Post date:** [April 7, 2021, 7:36am UTC](https://discuss.elastic.co/t/xml-parser-alter-field/269415/1 "2021-04-07T07:36:31Z")

</div>

Hi,

I have this setup for XML parser:

```auto
   xml {
    source => "message"
    target => "xml"
            add_field => {
                Audit_Type => "%{[xml][Audit_Type]}"
                Ext_Name => "%{[xml][Ext_Name]}"
        }
   }

```

For some documents the Ext\_Name is empty and this value is shown in the document in ELK:  
`%{[xml][Ext_Name]}`

To change that to "blank", I tried with this:

```auto
alter {
        condrewrite => [
"Ext_Name","%{[xml][Ext_Name]}",""

]
}

```

But this "%{[xml][Ext\_Name]}" is not working because logstash will see this as variable. Is there a way to escape this in the alter plugin that logstash see this as text and not as variable?

thx!

---

<div class="post-metadata">

**Author:** ![Soren\_vdc](https://avatars.discourse-cdn.com/v4/letter/s/b4bc9f/32.png) [@Soren\_vdc](https://discuss.elastic.co/u/Soren_vdc)\
**Post date:** [April 8, 2021, 7:28am UTC](https://discuss.elastic.co/t/xml-parser-alter-field/269415/2 "2021-04-08T07:28:28Z")

</div>

I can change it by IF function:  
` if "xml][Ext_Name" in [Ext_Name]{ mutate{ replace => {"Ext_Name" => ""} }`

But is there a procedure to search for the Value "xml][" in all fields and change to ""?

---

<div class="post-metadata">

**Author:** ![Cad](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cad/32/86661_2.png) [@Cad](https://discuss.elastic.co/u/Cad)\
**Post date:** [April 8, 2021, 8:54am UTC](https://discuss.elastic.co/t/xml-parser-alter-field/269415/3 "2021-04-08T08:54:21Z")

</div>

Hi,

Yes you can use gsub from mutate filter [documentation](https://www.elastic.co/guide/en/logstash/current/plugins-filters-mutate.html#plugins-filters-mutate-gsub)

```auto
mutate {
    gsub => [
         "Ext_Name", "xml][", ""
    ]
}

```

Cad

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [April 8, 2021, 3:55pm UTC](https://discuss.elastic.co/t/xml-parser-alter-field/269415/4 "2021-04-08T15:55:29Z")

</div>

You may be able to do this using a prune filter. The [default operation](https://www.elastic.co/guide/en/logstash/current/plugins-filters-prune.html#plugins-filters-prune-blacklist_names) of the filter is to remove any field that matches the regexp `%{[^}]+}`.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [May 6, 2021, 3:55pm UTC](https://discuss.elastic.co/t/xml-parser-alter-field/269415/5 "2021-05-06T15:55:35Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
