Here you can find the source of parse(XMLStreamReader reader, String... elementNames)
public static List<String> parse(XMLStreamReader reader, String... elementNames) throws XMLStreamException
//package com.java2s; //License from project: Apache License import static javax.xml.stream.XMLStreamConstants.END_DOCUMENT; import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamReader; public class Main { public static List<String> parse(XMLStreamReader reader, String... elementNames) throws XMLStreamException { Set<String> set = new HashSet<>(); for (String name : elementNames) { set.add(name);//from w ww .j a va 2 s . c o m } List<String> stateNames = new ArrayList<String>(); while (true) { if (reader.getEventType() == END_DOCUMENT) { break; } if (reader.getEventType() == START_ELEMENT) { String cursor = reader.getLocalName(); if (set.contains(cursor)) { reader.next(); String value = reader.getText(); stateNames.add(value); } } reader.next(); } return stateNames; } }