From 3e9c25b758c38d999d45794c81a58828d59461fd Mon Sep 17 00:00:00 2001 From: marcel Date: Sat, 1 Sep 2018 22:09:45 +0200 Subject: [PATCH] added README.md and travis status badge --- README.md | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..9880de1 --- /dev/null +++ b/README.md @@ -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 + + + + +``` +* 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 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! +