xml-reader


License

License

GroupId

GroupId

nl.elmar
ArtifactId

ArtifactId

xml-reader_2.12
Last Version

Last Version

0.12
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.12

How to add to project

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

Dependencies

compile (4)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.12.8
org.typelevel : cats-core_2.12 jar 2.0.0
com.chuusai : shapeless_2.12 jar 2.3.3
org.scala-lang.modules : scala-xml_2.12 jar 1.2.0

test (1)

Group / Artifact Type Version
org.scalatest : scalatest_2.12 jar 3.0.8

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.12
0.11
0.10
0.9
0.8
0.6
0.5
0.4