Giter VIP home page Giter VIP logo

siftxml's Introduction

SiftXml

SiftXml is a lightweight xml to java mapper parsed by kXML2 and using a minimal DSL inspired by the Go stdlib encoding/xml package. Regardless of the number of nested nodes, it allows you to sift out only the information you're interested in without having to design complex models.

Usage

Mapping is done by calling new SiftXml().parse(InputStream, Class);.

Additional options can be configured before calling .parse() as so:

new SiftXml()
    .setFeature(XmlPullParser.FEATURE_PROCESS_DOCDECL, true)
    .setFeature(XmlPullParser.FEATURE_VALIDATION, true)
    .parse(InputStream, Class);

Gradle

repositories {
    ivy {
        url 'https://raw.github.com/thesmythgroup/SiftXml/master/repo/'
    }
}

dependencies {
    compile "org.tsg.siftxml:siftxml:0.1-SNAPSHOT"
}

Basic

Xml

<root>
    <user>
        <name>John Doe</name>
        <email>[email protected]</email>
    </user>
</root>

Java

@Xml("root > user")
public class User {
    public String name;
    public String email;
}

Parse

User user = new SiftXml().parse(in, User.class);

Arrays

Xml

<root>
    <user>
        <name>John Doe</name>
        <email>[email protected]</email>
    </user>
    <user>
        <name>Jane Roe</name>
        <email>[email protected]</email>
    </user>
</root>

Java

@Xml("root")
public class Root {

    @Xml("user > name")
    public String[] names;

    @Xml("user > email")
    public String[] emails;
}

Parse

Root root = new SiftXml().parse(in, Root.class);
// the User class from the basic example above also works
User[] users = new SiftXml()parse(in, User[].class);

Inner Classes

Inner classes should be declared static so they are made available to the mapper.

Type Coercion

The type of a field is used when setting the value. Any class with a constructor that accepts a single String argument can be used. As an example, if a node's text was 1234 and a model's member was of type Integer, Integer.parseInt would be used when setting the member's value.

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.