I use scala.xml.PrettyPrinter to format my XML in Scala. The problem is with nodes without text content. Instead of this:
<node></node>
I’d prefer to have this:
<node />
How can I make PrettyPrinter to format it my way?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This was a bug in scala-xml, but it was fixed in version 1.1.0 on Feb-20-2018. A new option
minimizeEmptywas added toPrettyPrinter.To use 1.1.0, add the following to your
build.sbt:Here’s an example of how to make use of the new option in
PrettyPrinter:This will output:
If the Scala compiler, complains:
then you need to enable a forked JVM in sbt, so that Scala is using the new version of scala-xml. Just add the follow to your
build.sbt:Previous to scala-xml 1.1.0, the method to create
<node/>,leafTag(), is in the class, but unused. You can fix it like so:There’s no reason to use the override-hack if you can just upgrade to 1.1.0.