Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jonnyzzz/kotlin.xml.bind
Kotln XML binding DSL
https://github.com/jonnyzzz/kotlin.xml.bind
Last synced: 16 days ago
JSON representation
Kotln XML binding DSL
- Host: GitHub
- URL: https://github.com/jonnyzzz/kotlin.xml.bind
- Owner: jonnyzzz
- License: apache-2.0
- Created: 2015-12-20T20:40:02.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-12-26T08:10:57.000Z (almost 7 years ago)
- Last Synced: 2024-10-03T12:38:54.640Z (about 1 month ago)
- Language: Kotlin
- Homepage:
- Size: 144 KB
- Stars: 34
- Watchers: 3
- Forks: 8
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![Build Status](https://travis-ci.org/jonnyzzz/kotlin.xml.bind.svg?branch=master)](https://travis-ci.org/jonnyzzz/kotlin.xml.bind)
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 JDOMLicense
-------Apache 2.0
Binaries
========You may download binaries from maven artifacts repository from here
http://dl.bintray.com/jonnyzzz/mavenIn Gradle build script it may be done like this
```gradle
repositories {
maven { url "http://dl.bintray.com/jonnyzzz/maven" }
}dependencies {
compile "org.jonnyzzz.kotlin.xml.bind:jdom:"
}
```Usage example
-------------```kotlin
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)
}
```