Skip to content

Commit

Permalink
added README.md and travis status badge
Browse files Browse the repository at this point in the history
  • Loading branch information
marcel committed Sep 1, 2018
1 parent aaac2be commit 3e9c25b
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
## XML Iteration
This library provides classes for de/serializing collections/streams of objects to XML. It relies heavily on JAXB.

[![Build Status](https://travis-ci.org/thimmwork/xml-iteration.svg?branch=master)](https://travis-ci.org/thimmwork/xml-iteration)

### Deserialization
#### XMLIterator
Given an `InputStream` containing the XML
```xml
<fruits>
<fruit name="orange"/>
<fruit name="lemon"/>
</fruits>
```
* the XML element name `fruit` and
* a class `Fruit` with suitable JAXB annotations,

the XMLIterator streams the `InputStream` until it finds a closing tag of `fruit` and deserializes it to an instance of `Fruit`:
```
XMLIterator<Fruit> iterator = new XMLIterator<>(inputStream, Fruit.class, "fruit");
while (iterator.hasNext()) {
System.out.println(iterator.next().getName());
}
```
```
for (Fruit fruit : new XMLIterator<>(inputStream, Fruit.class, "fruit")) {
System.out.println(fruit.getName());
}
```
will result in the output
```text
orange
lemon
```
Iteration will occur on calls of `hasNext()` and continue until the end of the stream is reached.

Beware that if the stream is infinite and does not contain any matching element, the stream will iterate indefinitely!

0 comments on commit 3e9c25b

Please sign in to comment.