Et le source est toujours sur BitBucket :<dependency> <groupId>net.avcompris.commons</groupId> <artifactId>avc-binding-dom</artifactId> <version>0.1.10</version> </dependency>
https://bitbucket.org/avantage-compris/avc-binding-domRappel de son utilisation par un exemple :
Soit un document XML de la forme suivante :
Vous écrivez une interface Java de binding sous la forme suivante :<aaaa> <bbbb width="34" height="58"> <cccc weight="19k">one</cccc> <cccc weight="812m">two</cccc> <cccc weight="7x8">three</ccc> </bbbb> </aaaa>
interface Foo {
@XPath("bbbb/@width")
int getWidth();
@XPath("bbbb/@height")
int getHeight();
@XPath("cccc")
Bar[] getBars();
interface Bar {
@XPath("@weight")
String getWeight();
@XPath(".")
String getContent();
}
@XPath("cccc[@weight = $arg0]")
Bar getBarByWeight(String x);
}
Et vous pouvez alors écrire le code Java suivant, qui va directement puiser les valeurs dans le DOM :
Foo foo = DomBinderUtils.xmlContentToJava(..., Foo.class);
assertEquals(34, foo.getWidth());
assertEquals(3, foo.getBars().length);
assertEquals("19k", foo.getBars()[0].getWeight());
assertEquals("two", foo.getBarByWeight("812m").getContent());
Voir sur ce blog d’autres articles sur le même sujet :
- Une API de binding Java/XML : avc-binding-dom (juin 2013)
- avc-binding-dom et polymorphisme (janvier 2014)