Java tutorial
//package com.java2s; import javax.xml.stream.events.XMLEvent; import java.util.Iterator; import java.util.List; import java.util.Optional; public class Main { public static Optional<XMLEvent> getStartElement(List<XMLEvent> events, String elementName) { Iterator<XMLEvent> iterator = events.iterator(); while (iterator.hasNext()) { XMLEvent event = iterator.next(); if (event.isStartElement() && event.asStartElement().getName().getLocalPart().equals(elementName)) return Optional.of(event); } return Optional.empty(); } }