Coder Social home page Coder Social logo

free-form-xml-java-parser's Introduction

Free Form XML Java Parser

A very simple XML parser loosely binding text into the given Java class structure.

Written by zencd. Java7+.

Key features

  • Parsing done by a Java model, no annoytations needed
  • XML may come in different (free) forms but it gonna be parsed anyway

A sample model

public static class CarXml {
    public String color;
    public List<Wheel> wheel;
    public static class Wheel {
        public String name;
    }
}

Free form XML

Attributes

Setting a Java property could be done via an XML attribute, but also via a dedicated tag:

<root color='red'/>

<root>
    <color>red</color>
</root>

Collections

The full form:

<root>
    <wheels>
        <wheel name='one'/>
        <wheel name='two'/>
    </wheels>
</root>

Without the parent <wheels> it works too:

<root>
  <wheel name='one'/>
  <wheel name='two'/>
</root>

A special tag <item> automatically recognized as a <wheel> being inside a collection:

<root>
    <wheels>
        <item name='one'/>
    </wheels>
</root>

You may also mix all the approaches.

Parser usage

CarXml root = FreeFormXmlParser.parse(CarXml.class, xmlContent);

Also refer to tests like FreeFormXmlParserTest.

Setting Java properties in your way

See PropertyBinder and its derivation DefaultPropertyBinder.

TODO

  • Bind properties like some-prop to Java, and tag names also
  • Be able to bind 'NaMe' to 'NamE' (any forms)

free-form-xml-java-parser's People

Contributors

dependabot[bot] avatar zencd avatar

Watchers

 avatar  avatar

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.