Binding XML data in Scala
Even if XML has recently stepped down a bit from its ubiquitous position due to the increasing popularity of JSON, both formats will continue to be heavily used to structure data.
In Java, it is a common practice to use the JAXB libraries to create classes that are able to serialize and deserialize XML data and construct XML documents through an API.
In a similar manner, the scalaxb
library available for Scala can generate help classes for working with XML and web services. As an example, let's consider a small XML schema, Bookstore.xsd,
that defines a set of books as part of a book store as follows:
<?xml version="1.0" encoding="UTF-8"?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.books.org" xmlns="http://www.books.org" elementFormDefault="qualified"> <xsd:element name="book_store"> <xsd:complexType> <xsd:sequence> <...