Print arbitrary case classes and other values at runtime - into XML
Scala
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
project
src
.gitignore
README.md
build.sbt

README.md

XML Printing for Scala (xp4s)

No hand-writing of XML, very useful for rapid prototyping.

Including dependency

scalaVersion := "2.11.8"
resolvers += Resolver.bintrayRepo("scalawilliam", "maven")
libraryDependencies += "xp4s" %% "xp4s" % "0.2.2"

Example

import xp4s.modes.reflection._
case class Coat(brand: Option[String])
case class Human(title: String, name: String, coats: Seq[Coat])
val human = Human("Mr.", "Johnny", List(Coat(Option("BOSS")), Coat(None), Coat(Option("Armani"))))
val printer = new scala.xml.PrettyPrinter(80, 2)
println(printer.format(xp4s.XMLPrinter.print(human).head))

Gives:

<Human>
  <title>Mr.</title>
  <name>Johnny</name>
  <coats>
    <Coat>
      <brand>BOSS</brand>
    </Coat>
    <Coat/>
    <Coat>
      <brand>Armani</brand>
    </Coat>
  </coats>
</Human>