Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import javax.xml.stream.events.Characters;
import javax.xml.stream.events.XMLEvent;
import java.util.Iterator;
import java.util.List;
import java.util.Optional;

public class Main {
    public static Optional<Characters> getCharacterEventOfElement(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)) {
                XMLEvent nextEvent = iterator.next();
                if (nextEvent.isCharacters())
                    return Optional.of(nextEvent.asCharacters());
            }

        }

        return Optional.empty();
    }
}