Reasonable parser combinators for XML element streams


Build Status Maven Central

Reasonable parser combinators for XML element streams


libraryDependencies += "io.github.amrhassan" %% "exemelle" % "2.1.1"
import exemelle.StreamAction._
import exemelle.StreamParser

// You can describe how you want to process the stream in terms of combinators found in
// the StreamAction object

// Perhaps you want to capture the XML elements numbered 11 to 15?
val take5After10 = for {
    _ <- drop(10)
    elems <- take(5)
  } yield elems
// or drop everything until you encounter the "author" starting tag then take 5 elem?
import cats.implicits._   // For the >> shorthand
val dropUtilAuthor = dropUntil( == "author") >> take(5)

// Or the full tag named "book"?
val bookTag = findTagNamed("book")

// Or al the full tags named "book"?
val allBookTags = findAllTagsNamed("book")

// You need parser implementation to parse through your stream
val parser = StreamParser.fromInputStream(/* a */)

// Now you can run one of the actions you've constructed earlier
run(parser)(allBookTags) // runs it into an Either[StreamError, Vector[Tag]]