-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added README.md and travis status badge
- Loading branch information
marcel
committed
Sep 1, 2018
1 parent
aaac2be
commit 3e9c25b
Showing
1 changed file
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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! | ||
|