# Parsing XML with self-closing tags

**URL:** <https://discuss.elastic.co/t/parsing-xml-with-self-closing-tags/31723>\
**Category:** Logstash\
**Created:** [October 6, 2015, 6:56pm UTC](https://discuss.elastic.co/t/parsing-xml-with-self-closing-tags/31723 "2015-10-06T18:56:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![JW1](https://avatars.discourse-cdn.com/v4/letter/j/34f0e0/32.png) [@JW1](https://discuss.elastic.co/u/JW1)\
**Post date:** [October 6, 2015, 6:56pm UTC](https://discuss.elastic.co/t/parsing-xml-with-self-closing-tags/31723/1 "2015-10-06T18:56:22Z")

</div>

If I use logstash to parse XML with an self-closing tag (e.g. `<foo />`), it turns it into an empty object instead of an empty string. For example:

```
"parsed" => {
    "foo" => [
        [0] {}
    ]
}

```

How can I add a conditional to only call add\_field if it's a string, not an empty object? If I do this:

```
if [parsed][foo][0] {
    mutate {
        add_field => {
            "foo" => "%{[parsed][foo][0]}"
        }
    }
}

```

the field "foo" gets the value "{}". I also tried checking `if [parsed][foo][0] != "{}"`, but that didn't catch it.

---

<div class="post-metadata">

**Author:** ![mustafakirimli](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mustafakirimli/32/6823_2.png) [@mustafakirimli](https://discuss.elastic.co/u/mustafakirimli)\
**Post date:** [December 24, 2015, 9:21am UTC](https://discuss.elastic.co/t/parsing-xml-with-self-closing-tags/31723/2 "2015-12-24T09:21:12Z")

</div>

I'm not sure is it correct way or not, but i've solved this problem with removing empty (self closing) xml tags with mutate filter and gsub config. My code is below;

`mutate { gsub => ["message", "<(\s)?\w+(\s)?/>", ""] }`

---

<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:** [July 6, 2017, 5:17am UTC](https://discuss.elastic.co/t/parsing-xml-with-self-closing-tags/31723/3 "2017-07-06T05:17:22Z")

</div>

Closed on July 6, 2017, 5:17am UTC


