# Trouble parsing xml file

**URL:** <https://discuss.elastic.co/t/trouble-parsing-xml-file/153582>\
**Category:** Logstash\
**Created:** [October 23, 2018, 10:50am UTC](https://discuss.elastic.co/t/trouble-parsing-xml-file/153582 "2018-10-23T10:50:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Miguel\_Leite](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/miguel_leite/32/41988_2.png) [@Miguel\_Leite](https://discuss.elastic.co/u/Miguel_Leite)\
**Post date:** [October 23, 2018, 10:50am UTC](https://discuss.elastic.co/t/trouble-parsing-xml-file/153582/1 "2018-10-23T10:50:06Z")

</div>

Hey there,  
New to ELK and I was trying to parse the following xml file:

```
<msg time='2018-09-04T20:47:31.182+01:00' org_id='oracle' comp_id='rdbms'
 type='UNKNOWN' level='16' host_id='HHHHH'
 host_addr='XXX.XX.XXX.X' pid='YYYY' version='1'>
 <txt>Creating new log segment:
 </txt>
</msg>

```

I have the following logstash config file:

```
input {
        beats {
                port => 5044
        }
        if "xml" in [tags] {
                codec => multiline {
                        pattern => "<msg time"
                        negate => "true"
                        what => "next"
                }
        }
}
filter { 
       else if "xml" in [tags] {
                xml {
                        source => "message"
                        store_xml => false
                        xpath => [
                                   "/msg/text()", "msg_xml",
                                   "/msg/txt/text()", "txt_xml"
                        ]
                }
        }
}

```

Shouldn't it be working? The fields won't parse...

---

<div class="post-metadata">

**Author:** ![balumurari1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/balumurari1/32/39203_2.png) [@balumurari1](https://discuss.elastic.co/u/balumurari1)\
**Post date:** [October 24, 2018, 10:34am UTC](https://discuss.elastic.co/t/trouble-parsing-xml-file/153582/2 "2018-10-24T10:34:58Z")

</div>

hope this helps you,

> [@Unable to load xml file in logstash](https://discuss.elastic.co/t/unable-to-load-xml-file-in-logstash/151318/5):
>
> The correct output is obtained for below input code, hope this helps other people, Also, max\_lines number changes based on the maximum number of lines present in your xml file input { file { path =\> "C:/Users/LENOVO/Downloads/stations.xml" start\_position =\> "beginning" sincedb\_path =\> "NUL" codec =\> multiline { pattern =\> "^\<?stations.\*\>" negate =\> "true" what =\> "previous" auto\_flush\_interval =\> 1 max\_lines =\> 3000 } } } filter { xml { source =\> "message" target =\> "pars…

---

<div class="post-metadata">

**Author:** ![wwalker](https://avatars.discourse-cdn.com/v4/letter/w/43a26b/32.png) [@wwalker](https://discuss.elastic.co/u/wwalker)\
**Post date:** [October 24, 2018, 7:59pm UTC](https://discuss.elastic.co/t/trouble-parsing-xml-file/153582/3 "2018-10-24T19:59:20Z")

</div>

I believe your error is in your multiline codec config. You are saying if the pattern does not match `<msg`, stick it on the next line. So I think you're getting a bunch of `<msg time='2018-09-04T20:47:31.182+01:00' org_id='oracle' comp_id='rdbms'` lines with the rest of the relevant information being pushed down to the next line. Since it's not proper XML formatting, it probably throws a parsing error.

In the multiline codec config, change it to `what => "previous"`. That changes it to, "If the line does not start with `<msg time`, stick it on the previous line."

---

<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:** [November 21, 2018, 7:59pm UTC](https://discuss.elastic.co/t/trouble-parsing-xml-file/153582/4 "2018-11-21T19:59:23Z")

</div>

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