Java XMLStreamReader moveReaderToEndCurrentTag(XMLStreamReader reader)

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

Description

Moves the reader to the closing tag of current tag.

License

GNU General Public License

Parameter

Parameter Description
reader XMLStreamReader which should be moved

Exception

Parameter Description
XMLStreamException when parse exception occurs

Declaration

public static void moveReaderToEndCurrentTag(XMLStreamReader reader) throws XMLStreamException 

Method Source Code

//package com.java2s;
// License: GPL. For details, see LICENSE file.

import javax.xml.namespace.QName;

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

public class Main {
    /**/* w w w  .j  a va2  s.  c  om*/
     * Moves the reader to the closing tag of current tag.
     * @param reader XMLStreamReader which should be moved
     * @throws XMLStreamException when parse exception occurs
     */
    public static void moveReaderToEndCurrentTag(XMLStreamReader reader) throws XMLStreamException {
        int level = 0;
        QName tag = reader.getName();
        for (int event = reader.getEventType(); reader.hasNext(); event = reader.next()) {
            if (XMLStreamReader.START_ELEMENT == event) {
                level += 1;
            } else if (XMLStreamReader.END_ELEMENT == event) {
                level -= 1;
                if (level == 0 && tag.equals(reader.getName())) {
                    return;
                }
            }
            if (level < 0) {
                throw new IllegalStateException(
                        "WMTS Parser error - moveReaderToEndCurrentTag failed to find closing tag");
            }
        }
        throw new IllegalStateException("WMTS Parser error - moveReaderToEndCurrentTag failed to find closing tag");
    }
}

Related

  1. isContextual(XMLStreamReader input)
  2. isEndTag(XMLStreamReader reader, String tagLocalName)
  3. isStartTag(XMLStreamReader reader)
  4. logReader(Logger logger, String msg, XMLStreamReader reader)
  5. move(XMLStreamReader reader)
  6. printEvent(XMLStreamReader xmlr)
  7. printEvent(XMLStreamReader xmlr, boolean showEvents)
  8. printLiterally(final PrintStream os, final XMLStreamReader xmlReader)
  9. printText(XMLStreamReader xmlr)