Skip to content

zero dependency library for iterative xml de-/serialization

License

Notifications You must be signed in to change notification settings

thimmwork/xml-iteration

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

XML Iteration

This library provides classes for de/serializing collections/streams of objects to XML. It relies heavily on JAXB.

Build Status

Deserialization

XMLIterator

Given an InputStream containing the 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

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!

About

zero dependency library for iterative xml de-/serialization

Resources

License

Stars

Watchers

Forks

Packages

No packages published