# How to parse few XML files with different number of tags in different files using Logstash?

**URL:** <https://discuss.elastic.co/t/how-to-parse-few-xml-files-with-different-number-of-tags-in-different-files-using-logstash/228156>\
**Category:** Logstash\
**Created:** [April 15, 2020, 3:34pm UTC](https://discuss.elastic.co/t/how-to-parse-few-xml-files-with-different-number-of-tags-in-different-files-using-logstash/228156 "2020-04-15T15:34:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gerych](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gerych/32/47806_2.png) [@Gerych](https://discuss.elastic.co/u/Gerych)\
**Post date:** [April 15, 2020, 3:34pm UTC](https://discuss.elastic.co/t/how-to-parse-few-xml-files-with-different-number-of-tags-in-different-files-using-logstash/228156/1 "2020-04-15T15:34:51Z")

</div>

Can someone tell me how you can parse these types of files through the logstash and after that index it in elasticsearch. Files can contain a variable number of internal tags.

 ![Untitled](https://us1.discourse-cdn.com/elastic/original/3X/3/d/3d1715dd4521d64371006d3dfd49f0e6bb04a2f6.png)  
Here is my config file, but unfortunately it does not work correctly.

```auto
input {
        file {
            path => "/folder/etlexpmx.xml"
            start_position => "beginning"
            sincedb_path => "/dev/null"
            exclude => "*.gz"
            type => "xml"
            codec => multiline {
                pattern => "^<\? PMSetup .*\>" 
                negate => "true"
                what => "previous"
            }
        }
    }

    filter {
        xml { source => "message" target => "PMSetup" force_array => "false"}
    }

    output {
        elasticsearch {
            codec => json
            hosts => "localhost"
            index => "TESTetlexpmx"
        }
        stdout {
            codec => rubydebug
        }
    }

```

I want to get the structure as:  
startTime = "2019-05-30T15: 00: 00.000 + 02: 00: 00"  
BMF = 400495  
BTF = 610  
measurementType = "PABTS"  
c123000 = 125483  
But as a result, the index is not created in elastisearch

---

<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 15, 2020, 3:43pm UTC](https://discuss.elastic.co/t/how-to-parse-few-xml-files-with-different-number-of-tags-in-different-files-using-logstash/228156/2 "2020-04-15T15:43:31Z")

</div>

I would use a pattern that never matches so that you can consume the entire file as a single event. See [here](https://discuss.elastic.co/t/logstash-xml-filter-not-working-properly/176758/10) for an example.

---

<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 13, 2020, 3:43pm UTC](https://discuss.elastic.co/t/how-to-parse-few-xml-files-with-different-number-of-tags-in-different-files-using-logstash/228156/3 "2020-05-13T15:43:34Z")

</div>

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