Java XML Parse Stream parse(XMLStreamReader reader, String... elementNames)

Here you can find the source of parse(XMLStreamReader reader, String... elementNames)

Description

parse

License

Apache License

Declaration

public static List<String> parse(XMLStreamReader reader, String... elementNames) throws XMLStreamException 

Method Source Code


//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;
    }
}

Related

  1. parse(InputStream is)
  2. parse(InputStream is)
  3. parse(InputStream s, boolean validateIfSchema)
  4. parse(InputStream stream)
  5. parse(XMLStreamReader reader)
  6. parseDoc(final InputStream is)
  7. parseInputStream(InputStream in, boolean namespaces, boolean validating)
  8. parseInputStream(InputStream is)
  9. parseMulXML( InputStream is, String[] tagNames)