Thimmwork XML-Iteration

a lightweight collection of utilities for iterating and parsing xml streams based on JAXB

License

License

Categories

Categories

Net
GroupId

GroupId

net.thimmwork
ArtifactId

ArtifactId

xml-iteration
Last Version

Last Version

1.0
Release Date

Release Date

Type

Type

jar
Description

Description

Thimmwork XML-Iteration
a lightweight collection of utilities for iterating and parsing xml streams based on JAXB
Project URL

Project URL

https://github.com/thimmwork/xml-iteration
Source Code Management

Source Code Management

https://github.com/thimmwork/xml-iteration/tree/master

Download xml-iteration

How to add to project

<!-- https://jarcasting.com/artifacts/net.thimmwork/xml-iteration/ -->
<dependency>
    <groupId>net.thimmwork</groupId>
    <artifactId>xml-iteration</artifactId>
    <version>1.0</version>
</dependency>
// https://jarcasting.com/artifacts/net.thimmwork/xml-iteration/
implementation 'net.thimmwork:xml-iteration:1.0'
// https://jarcasting.com/artifacts/net.thimmwork/xml-iteration/
implementation ("net.thimmwork:xml-iteration:1.0")
'net.thimmwork:xml-iteration:jar:1.0'
<dependency org="net.thimmwork" name="xml-iteration" rev="1.0">
  <artifact name="xml-iteration" type="jar" />
</dependency>
@Grapes(
@Grab(group='net.thimmwork', module='xml-iteration', version='1.0')
)
libraryDependencies += "net.thimmwork" % "xml-iteration" % "1.0"
[net.thimmwork/xml-iteration "1.0"]

Dependencies

compile (2)

Group / Artifact Type Version
org.jetbrains.kotlin : kotlin-stdlib-jdk8 jar 1.2.30
junit : junit jar 4.12

Project Modules

There are no modules declared in this project.

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!

Versions

Version
1.0