# IF condition with XML filter

**URL:** <https://discuss.elastic.co/t/if-condition-with-xml-filter/106877>\
**Category:** Logstash\
**Created:** [November 8, 2017, 1:55pm UTC](https://discuss.elastic.co/t/if-condition-with-xml-filter/106877 "2017-11-08T13:55:34Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![rm1890](https://avatars.discourse-cdn.com/v4/letter/r/85e7bf/32.png) [@rm1890](https://discuss.elastic.co/u/rm1890)\
**Post date:** [November 8, 2017, 1:55pm UTC](https://discuss.elastic.co/t/if-condition-with-xml-filter/106877/1 "2017-11-08T13:55:34Z")

</div>

hi all,

I'm trying to apply an XML filter based on the value of one of the fields. So, the config for that part looks like this:

```
      filter{
                if [my_field] == "x.zhh"{
                xml{
                store_xml => "false"
                source => "[myxml][payload][xml]"

                xpath => ["/testData/name/@type","Type"]

                remove_namespaces => "true"
                }
                }
        mutate{
                add_field => {"test_IF" => "TEST"}
                }
}

```

Somehow, the XML filter is ignored and I see only the output of mutate function. I checked and the field my\_field has value.

Not sure what exactly is wrong with the config. Can anyone help with this?

Thanks

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [November 8, 2017, 2:10pm UTC](https://discuss.elastic.co/t/if-condition-with-xml-filter/106877/2 "2017-11-08T14:10:52Z")

</div>

Please show an example event. Use a `stdout { codec => rubydebug }` output.

---

<div class="post-metadata">

**Author:** ![rm1890](https://avatars.discourse-cdn.com/v4/letter/r/85e7bf/32.png) [@rm1890](https://discuss.elastic.co/u/rm1890)\
**Post date:** [November 8, 2017, 2:23pm UTC](https://discuss.elastic.co/t/if-condition-with-xml-filter/106877/3 "2017-11-08T14:23:26Z")

</div>

ok, so, xml content looks like the following:

```
<Xmlns:testData http://example.com test:myField="x.zhh">
<test:name type="55">
<test:text test:content="222"/>
</test:data1>
<test:year test:content="1999"/>
</test:year>
</testData>

```

applying the xml filer without any IF condition works fine, but whenever I add the condition it just ignores the xml filter.

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [November 8, 2017, 2:46pm UTC](https://discuss.elastic.co/t/if-condition-with-xml-filter/106877/4 "2017-11-08T14:46:57Z")

</div>

I'd like to see the output from `stdout { codec => rubydebug }`.

---

<div class="post-metadata">

**Author:** ![rm1890](https://avatars.discourse-cdn.com/v4/letter/r/85e7bf/32.png) [@rm1890](https://discuss.elastic.co/u/rm1890)\
**Post date:** [November 8, 2017, 2:55pm UTC](https://discuss.elastic.co/t/if-condition-with-xml-filter/106877/5 "2017-11-08T14:55:15Z")

</div>

it's solved now. i didn't comment out the part of removing some fields. 🙂 sorry.

Thanks for the help though!

---

<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:** [December 6, 2017, 2:55pm UTC](https://discuss.elastic.co/t/if-condition-with-xml-filter/106877/6 "2017-12-06T14:55:30Z")

</div>

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