Java tutorial
//package com.java2s; //License from project: Open Source License import java.util.Optional; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamReader; public class Main { @SuppressWarnings("empty-statement") public static Optional<String> nextTag(XMLStreamReader reader) throws XMLStreamException { while (reader.hasNext() && reader.next() != XMLStreamReader.START_ELEMENT) ; if (reader.getEventType() == XMLStreamReader.END_DOCUMENT) { return Optional.empty(); } else { return Optional.of(reader.getName().getLocalPart()); } } }