Git Product home page Git Product logo

kotlin.xml.bind's Introduction

Build Status

Kotlin XML data binding DSL

This is a tiny library that allows one to generate XML files via Kotlin DSLs. The framework is build upon delegated properties.

Project consists of API module with no dependencies from any XML implementations. There is an implementation module that implements API via JDOM

License

Apache 2.0

Binaries

You may download binaries from maven artifacts repository from here http://dl.bintray.com/jonnyzzz/maven

In Gradle build script it may be done like this

repositories {
  maven { url "http://dl.bintray.com/jonnyzzz/maven" }
}

dependencies {
  compile "org.jonnyzzz.kotlin.xml.bind:jdom:<VERSION>"
}

Usage example

class Example {
  //declares a property of type String that load data from "ROOT/aaa/ggg/text()"
  var content by JXML / "aaa" / "ggg" / XText

  //same, but for attribute value
  var attribute by JXML / "aaa" / XAttribute("yohoho")

  //parses sub-object fields
  var sub by JXML / "sub" / XSub(Sub::class.java)

  //collection (aka List<>) of strings is loaded here
  var collection by JXML / "parameters" / XElements("param") / "aaa" / XText

  //collection (aka List<>) of sub objects
  var any by JXML / "parameters" / XAnyElements / XSub(Sub::class.java)
}

class Sub {
  // [2] --- allows to define persist order
  var key by JXML[2] / XAttribute("key")

  // this specifies default value
  var value by JXML[1] / XAttribute("value") - "defaultValue"

  // sometimes a part of XML should be loaded as-is. Type is org.jdom.Element
  var unknown by JXML / XUnknown
}

///Usage examples
fun test() {
  val e = Example()

  /// save to XML
  val saved = JDOM.save(e)

  /// load from XML
  val copy = JDOM.load(saved, Example::class.java)
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.