xml-reader


License

License

GroupId

GroupId

nl.elmar
ArtifactId

ArtifactId

xml-reader_2.11
Last Version

Last Version

0.8
Release Date

Release Date

Type

Type

jar
Description

Description

xml-reader
xml-reader
Project URL

Project URL

https://github.com/elmarreizen/xml-reader
Project Organization

Project Organization

nl.elmar
Source Code Management

Source Code Management

https://github.com/elmarreizen/xml-reader

Download xml-reader_2.11

How to add to project

<!-- https://jarcasting.com/artifacts/nl.elmar/xml-reader_2.11/ -->
<dependency>
    <groupId>nl.elmar</groupId>
    <artifactId>xml-reader_2.11</artifactId>
    <version>0.8</version>
</dependency>
// https://jarcasting.com/artifacts/nl.elmar/xml-reader_2.11/
implementation 'nl.elmar:xml-reader_2.11:0.8'
// https://jarcasting.com/artifacts/nl.elmar/xml-reader_2.11/
implementation ("nl.elmar:xml-reader_2.11:0.8")
'nl.elmar:xml-reader_2.11:jar:0.8'
<dependency org="nl.elmar" name="xml-reader_2.11" rev="0.8">
  <artifact name="xml-reader_2.11" type="jar" />
</dependency>
@Grapes(
@Grab(group='nl.elmar', module='xml-reader_2.11', version='0.8')
)
libraryDependencies += "nl.elmar" % "xml-reader_2.11" % "0.8"
[nl.elmar/xml-reader_2.11 "0.8"]

Dependencies

compile (4)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.11.12
org.typelevel : cats-core_2.11 jar 1.1.0
com.chuusai : shapeless_2.11 jar 2.3.3
org.scala-lang.modules : scala-xml_2.11 jar 1.1.1

test (1)

Group / Artifact Type Version
org.scalatest : scalatest_2.11 jar 3.0.4

Project Modules

There are no modules declared in this project.

Build Status

xml-reader

Xml reader helps to convert xml documents into domain classes.

import nl.elmar.xml.reader._
import XmlPath._
import cats.syntax.cartesian._

case class Author(name: String)
case class Book(title: String, year: Int, author: List[Author])
case class Library(book: List[Book])

implicit val authorReader: Reader[Author] = 
  __.read[String] map Author
  
implicit val bookReader: Reader[Book] = 
  (__ \ "title").read[String] |@|
  (__ \ "year").read[Int] |@|
  (__ \ "author").read[List[Author]] map Book
  
val libraryReader: Reader[Library] = 
  (__ \ "book").read[List[Book]] map Library
  
libraryReader(
  <library>
    <book>
      <title>Programming in Scala, Third Edition</title>
      <year>2016</year>
      <author>Martin Odersky</author>
      <author>Lex Spoon</author>
      <author>Bill Venners</author>
    </book>
  </library>
)

The same result could have been achieved with:

import nl.elmar.xml.reader._
import GenericReader._

implicit val authorReader: Reader[Author] = 
  __.read[String] map Author
  
implicit val bookReader = Reader.reader[Book]

val libraryReader = Reader.reader[Library]

Thanks to davegurnell for his awesome shapeless guide.

nl.elmar

VakantieDiscounter

Versions

Version
0.8