Example usage for javax.xml.stream XMLStreamReader getEventType

List of usage examples for javax.xml.stream XMLStreamReader getEventType

Introduction

In this page you can find the example usage for javax.xml.stream XMLStreamReader getEventType.

Prototype

public int getEventType();

Source Link

Document

Returns an integer code that indicates the type of the event the cursor is pointing to.

Usage

From source file:XMLStreamReaderDemo.java

private static void process(XMLStreamReader reader) {
    int eventType = reader.getEventType();
    switch (eventType) {
    case XMLStreamConstants.START_ELEMENT:
        System.out.println("Start element: " + reader.getLocalName());

        int count = reader.getAttributeCount();
        for (int i = 0; i < count; i++) {
            String name = reader.getAttributeLocalName(i);
            String value = reader.getAttributeValue(i);
            System.out.println("\tAttribute name/value: " + name + "/" + value);
        }//from   ww w.j a  va  2s  .c  o m
        break;

    case XMLStreamConstants.END_ELEMENT:
        System.out.println("End element: " + reader.getLocalName());
        break;

    case XMLStreamConstants.CHARACTERS:
        System.out.println("Text: " + reader.getText());
        break;
    default:
        break;
    }
}

From source file:Main.java

private static void positionXMLStreamReaderAtAnyElement(XMLStreamReader xsr) throws Exception {
    while (xsr.hasNext()) {
        if (xsr.getEventType() == XMLStreamReader.START_ELEMENT && "ANY-ELEMENT".equals(xsr.getLocalName())) {
            break;
        }/*from  www.j  av  a 2s. c om*/
        xsr.next();
    }
}

From source file:Main.java

public static boolean isStartElement(final XMLStreamReader reader) {
    return reader.getEventType() == XMLStreamReader.START_ELEMENT;
}

From source file:Main.java

public static void printStartDocument(XMLStreamReader xmlr) {
    if (XMLStreamConstants.START_DOCUMENT == xmlr.getEventType()) {
        System.out.println("<?xml version=\"" + xmlr.getVersion() + "\"" + " encoding=\""
                + xmlr.getCharacterEncodingScheme() + "\"" + "?>");
    }// w  ww.jav  a2  s  .c o m
}

From source file:Main.java

public static boolean isEndOfElement(final XMLStreamReader reader, final String name) {
    return reader.getEventType() == XMLStreamReader.END_ELEMENT && reader.getName().getLocalPart().equals(name);
}

From source file:Main.java

/**
 * Test if reader is on a start tag.//from www .  ja v  a2 s. com
 *
 * @param reader xml stream reader
 * @return true if reader is on a start tag
 */
public static boolean isStartTag(XMLStreamReader reader) {
    return (reader.getEventType() == XMLStreamConstants.START_ELEMENT);
}

From source file:Main.java

public static boolean skipToElement(XMLStreamReader in) throws XMLStreamException {
    for (int code = in.getEventType(); code != XMLStreamReader.END_DOCUMENT; code = in.next()) {
        if (code == XMLStreamReader.START_ELEMENT || code == XMLStreamReader.END_ELEMENT) {
            return true;
        }// w ww. j  av a2s . c  o  m
    }
    return false;
}

From source file:Main.java

/**
 * Test if reader is on an end tag named tagLocalName.
 *
 * @param reader       xml stream reader
 * @param tagLocalName tag local name/*from   w  w  w .  j  a  va  2s  .co m*/
 * @return true if reader is on an end tag named tagLocalName
 */
public static boolean isEndTag(XMLStreamReader reader, String tagLocalName) {
    return (reader.getEventType() == XMLStreamConstants.END_ELEMENT)
            && (reader.getLocalName().equals(tagLocalName));
}

From source file:Main.java

/**
 * Advance the reader to the next end element and return true. Return false if next end element is not found
 * @param reader a XMLStreamReader/*from  w w  w.  java  2  s .c o  m*/
 * @return True when successfully advanced the reader.
 * @throws XMLStreamException Exception when reading from the XMLStreamReader fails.
 */
public static boolean advanceToNextEndElement(XMLStreamReader reader) throws XMLStreamException {
    while (reader.getEventType() != XMLStreamConstants.END_ELEMENT) {
        if (reader.hasNext()) {
            reader.next();
        } else {
            // reach the end of elements in reader. Not found.
            return false;
        }
    }
    return true;
}

From source file:Main.java

public static String getStateName(XMLStreamReader reader) {
    /* 215 */return getStateName(reader.getEventType());
    /*     */}