Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert Scala object to XML

Tags:

xml

scala

There are numerous Scala libraries to convert arbitrary objects to JSON and a few to convert JSON to XML, but I can't seem to find a nice way to convert arbitrary objects to XML. What's a good approach?

like image 538
Josh Avatar asked Dec 02 '11 17:12

Josh


2 Answers

I used scalaxb a while ago. It works very well if you have an XSD (or WSDL) as input to generate your classes. If this is the case, I also recommend using it.

Since you're also talking about JSON it may be that you have a web application using REST. In this case, have a look at Lift's REST-Support. For instance, if you use one of its internal persistency frameworks then all your entity types get a toXML method for free.

A third possibility would be to write your own conversion using Scala's XML literals.

Btw possible duplicates on Stack Overflow: Scala XML serialization and Which XML serialization library for Scala?

like image 169
Silas Avatar answered Nov 02 '22 04:11

Silas


Check this project: https://github.com/geirolz/advxml

It's a simple library based on RuleTransformer(standard scala xml library) and Cats with the aim to simplify the XML transformation and serialization/deserialization.

like image 32
David Geirola Avatar answered Nov 02 '22 02:11

David Geirola