XML Libraries

Bindings to new Scala XML DOM librariy can be added by implementing the DocumentBuilder and DocumentEventifier traites. fs2-data provides some of them out of the box.

scala-xml

Module: Maven Central

The fs2-data-xml-scala module provides DocumentBuilder and DocumentEventifier instances for the scala-xml Document type.

The documents Pipe emits scala.xml.Documents.

import fs2.{Fallible, Stream}
import fs2.data.xml._
import fs2.data.xml.dom._
import fs2.data.xml.scalaXml._

val input = """<?xml version="1.1" ?>
              |<root attr1="value1" attr2="value2">
              |  <!-- a comment -->
              |  Some text &amp; a child.
              |  <nested>With text</nested>
              |</root>""".stripMargin
// input: String = <?xml version="1.1" ?>
// <root attr1="value1" attr2="value2">
//   <!-- a comment -->
//   Some text &amp; a child.
//   <nested>With text</nested>
// </root>

val evts = Stream.emits(input)
                 .through(events[Fallible, Char]())
                 .through(documents)
// evts: Stream[[x]Fallible[x], xml.Document] = Stream(..)

evts.compile.toList
// res0: Either[Throwable, List[xml.Document]] = Right(List(<root attr1="value1" attr2="value2">
//   
//   Some text &amp; a child.
//   <nested>With text</nested>
// </root>))