# Parse Error while parsing JUnit XML

**URL:** <https://discuss.elastic.co/t/parse-error-while-parsing-junit-xml/164037>\
**Category:** Logstash\
**Created:** [January 13, 2019, 12:35pm UTC](https://discuss.elastic.co/t/parse-error-while-parsing-junit-xml/164037 "2019-01-13T12:35:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rohin\_Gopalakrishnan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rohin_gopalakrishnan/32/39732_2.png) [@Rohin\_Gopalakrishnan](https://discuss.elastic.co/u/Rohin_Gopalakrishnan)\
**Post date:** [January 13, 2019, 12:35pm UTC](https://discuss.elastic.co/t/parse-error-while-parsing-junit-xml/164037/1 "2019-01-13T12:35:47Z")

</div>

I am trying to parse a JUnit XML and I always get the \_xmlparsefailure stating the reason as  
`Preformatted text:exception=>#<REXML::ParseException: Declarations can only occur in the doctype declaration.`

The below configuration works for other JUnit XML's however certain XML have a parse failure.

```
# logstash.conf

input {
  beats {
    port => 5044
  }
}

filter {

  xml {
     source => "message"
     store_xml => true 
     force_content => true
     target => "parsed"
  }
}
  
output {
  stdout { codec => rubydebug }
}

```

Sample JUnit XML that fails is available here - [https://pastebin.com/CdbVtZ0n](https://pastebin.com/CdbVtZ0n)  
Note: I have noticed that when I remove the data in `<system-out>` before sending in the file, it works as it should. I think somehow the XML filter is trying to parse the data inside the CDATA which it should not.

I had also tried to remove the system-out tag before parsing with gsub filter as below, this would however only successfully remove in the case of a successfully parsed xml. For the XML above, the parse would still fail.

```
  mutate {
    gsub => [
      "message", "<system-out>[\s\S]*?<\/system-out>", "<replaced-sys-ot>M</replaced-sys-ot>"
    ]
  }

```

Any help is greatly appreciated! Thank you 🙂

---

<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:** [February 10, 2019, 12:35pm UTC](https://discuss.elastic.co/t/parse-error-while-parsing-junit-xml/164037/2 "2019-02-10T12:35:48Z")

</div>

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