Java XMLStreamReader getNextEvent(XMLStreamReader reader)

Here you can find the source of getNextEvent(XMLStreamReader reader)

Description

Returns the next relevant reader event.

License

Apache License

Parameter

Parameter Description
reader a parameter

Exception

Parameter Description
XMLStreamException an exception

Declaration

private static int getNextEvent(XMLStreamReader reader) throws XMLStreamException 

Method Source Code

//package com.java2s;
/**//from ww w.j  a  v  a  2s. c o  m
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements. See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership. The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;

public class Main {
    /**
     * Returns the next relevant reader event.
     *  
     * @param reader
     * @return
     * @throws XMLStreamException
     */
    private static int getNextEvent(XMLStreamReader reader) throws XMLStreamException {
        while (reader.hasNext()) {
            int e = reader.next();
            if (e == XMLStreamConstants.END_DOCUMENT) {
                return e;
            }
            if (e == XMLStreamConstants.START_ELEMENT || e == XMLStreamConstants.END_ELEMENT) {
                return e;
            } else if (e == XMLStreamConstants.CHARACTERS) {
                String text = reader.getText();
                if (text.trim().length() == 0) {
                    continue;
                }
                return e;
            }
        }
        return -1;
    }
}

Related

  1. createXMLStreamReader(File file)
  2. createXMLStreamReader(InputStream in)
  3. createXMLStreamReader(InputStream in, String encoding)
  4. createXMLStreamReaderFromReader(final Reader reader)
  5. decodeAsDataHandler(XMLStreamReader reader, AttachmentUnmarshaller au)
  6. getXMLStreamReader(File file)
  7. getXMLStreamReader(InputStream is)
  8. getXSIType(XMLStreamReader reader)
  9. isContextual(XMLStreamReader input)