Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A very lenient XML parser for Java binding text into the given model

NotificationsYou must be signed in to change notification settings

zencd/free-form-xml-java-parser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 

Repository files navigation

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

Written byzencd. 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 likeFreeFormXmlParserTest.

Setting Java properties in your way

SeePropertyBinder and its derivationDefaultPropertyBinder.

TODO

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

About

A very lenient XML parser for Java binding text into the given model

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp