I know Java stax parser works with InputStreams. However, I would need to manually push chunks of strings to the parser instead of inputstream.
Would it be possible?
Kind regards,
I know Java stax parser works with InputStreams. However, I would need to manually push chunks of strings to the parser instead of inputstream.
Would it be possible?
Kind regards,
You can use a ByteArrayInputStream
wrapping around your String
chunks' bytes.
Quick example
XMLInputFactory factory = XMLInputFactory.newFactory();
XMLStreamReader reader = factory.createXMLStreamReader(
new ByteArrayInputStream("<start></start>".getBytes("UTF-8"))
);
while (reader.hasNext()) {
int event = reader.next();
switch (event) {
case (XMLStreamConstants.START_ELEMENT): {
System.out.println(reader.getLocalName());
break;
}
}
}
Output
start