# How to handle XML file "Last ## unconsumed characters" error

**URL:** https://discuss.elastic.co/t/how-to-handle-xml-file-last-unconsumed-characters-error/188385
**Category:** Logstash
**Created:** [July 1, 2019, 6:27pm UTC](https://discuss.elastic.co/t/how-to-handle-xml-file-last-unconsumed-characters-error/188385 "2019-07-01T18:27:09Z")
**Posts on this page:** 1
**Showing post:** 11

<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: [July 12, 2019, 7:04pm UTC](https://discuss.elastic.co/t/how-to-handle-xml-file-last-unconsumed-characters-error/188385/11 "2019-07-12T19:04:23Z")

</div>

I would expect mutate+gsub to be able to do it. For example, to remove the \<?xml version... you could use

```
    mutate { gsub => [ "message", "^<\?xml[^
]+
", "" ] }

```

Use literal newlines inside the pattern. So that is start of line, followed by \<?xml followed by one or more not-newline followed by newline.

---

_[View the full topic](https://discuss.elastic.co/t/how-to-handle-xml-file-last-unconsumed-characters-error/188385)._
