# XML parsing from entity bytestring

**URL:** <https://discuss.akka.io/t/xml-parsing-from-entity-bytestring/5286>\
**Category:** Akka Streams & Alpakka\
**Tags:** akka-http\
**Created:** [October 23, 2019, 11:01am UTC](https://discuss.akka.io/t/xml-parsing-from-entity-bytestring/5286 "2019-10-23T11:01:17Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![arempter](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.akka.io/arempter/32/1644_2.png) [@arempter](https://discuss.akka.io/u/arempter)\
**Post date:** [October 23, 2019, 11:01am UTC](https://discuss.akka.io/t/xml-parsing-from-entity-bytestring/5286/1 "2019-10-23T11:01:17Z")

</div>

Hello,

While using akka-stream-alpakka-xml with akka http requests, I noticed interesting behavior when parsing large xml files.

Detailed scenario is as follows:

- user posts xml file using akka http endpoint
- xml is then taken from request entity as bytestring source and parsed by XmlParsing.parser

XmlParsing logic works with the same xml without akka http, or when I first materialize it by Unmarshal(httpRequest.entity).to[String] and pass it as Source.single(Bytestring) to XmlParsing.parser.

When I run source.via(XmlParsing.parser), where source is from akka http request (request.entity.dataBytes), I almost always see that some keys from xml are splitted:

testuser/one/two/three/four/five/six/seven/eight/nine/ten/eleven/twelve/sub736/KM8DaDXEVNP4MByygsM8d5vK96NStFJC=87i and  
zFQw0lL90.txt

I susspect that this is related to fact that parsing is faster then source?

What do you think?

---

<div class="post-metadata">

**Author:** ![arempter](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.akka.io/arempter/32/1644_2.png) [@arempter](https://discuss.akka.io/u/arempter)\
**Post date:** [October 23, 2019, 11:13am UTC](https://discuss.akka.io/t/xml-parsing-from-entity-bytestring/5286/2 "2019-10-23T11:13:17Z")

</div>

if this helps, I have a working code in

> **[arempter/alpakka\_xml\_bug](https://github.com/arempter/alpakka_xml_bug)**
>
> Contribute to arempter/alpakka\_xml\_bug development by creating an account on GitHub.

if you run curl -XPOST [http://localhost:8123](http://localhost:8123) -d @large.xml two or more times you should see line split

---

<div class="post-metadata">

**Author:** ![ennru](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.akka.io/ennru/32/1495_2.png) [@ennru](https://discuss.akka.io/u/ennru)\
**Post date:** [October 25, 2019, 1:40pm UTC](https://discuss.akka.io/t/xml-parsing-from-entity-bytestring/5286/3 "2019-10-25T13:40:00Z")

</div>

Hi @arempter

Is it that you get several consecutive `TextEvent`s?  
That may happen when the source delivers the data in “chopped up” `ByteString`s as it doesn’t know about the structure. The parser does not try to aggregate data internally until a text section ends.

Cheers,  
Enno.

---

<div class="post-metadata">

**Author:** ![arempter](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.akka.io/arempter/32/1644_2.png) [@arempter](https://discuss.akka.io/u/arempter)\
**Post date:** [October 29, 2019, 8:22am UTC](https://discuss.akka.io/t/xml-parsing-from-entity-bytestring/5286/4 "2019-10-29T08:22:43Z")

</div>

Hi @ennru,

thanks for response. yes indeed I think I get two textEvents…  
It also looks like source is not divided randomly, but more like on buffer size or something

---

<div class="post-metadata">

**Author:** ![ennru](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.akka.io/ennru/32/1495_2.png) [@ennru](https://discuss.akka.io/u/ennru)\
**Post date:** [October 31, 2019, 9:45am UTC](https://discuss.akka.io/t/xml-parsing-from-entity-bytestring/5286/5 "2019-10-31T09:45:15Z")

</div>

If you need to get those into a single event, you could collapse consecutive `TextEvent`s by adding a `statefulMapConcat`.

Enno.

---

<div class="post-metadata">

**Author:** ![arempter](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.akka.io/arempter/32/1644_2.png) [@arempter](https://discuss.akka.io/u/arempter)\
**Post date:** [November 5, 2019, 6:48am UTC](https://discuss.akka.io/t/xml-parsing-from-entity-bytestring/5286/6 "2019-11-05T06:48:06Z")

</div>

cool, thanks for help
