Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import static javax.xml.stream.XMLStreamConstants.*;

import javax.xml.stream.XMLStreamReader;

public class Main {
    /**
     * Test if the current event is an element end tag with the given namespace and name.
     * If the namespace URI is null it is not checked for equality,
     * if the local name is null it is not checked for equality.
     * @param reader must not be {@code null}
     * @param uri the namespace uri of the element, may be null
     * @param name the local name of the element, may be null
     * @return true if the required values are matched, false otherwise
     */
    public static boolean isEndElement(XMLStreamReader reader, String uri, String name) {
        return isElement(reader, END_ELEMENT, uri, name);
    }

    /**
     * Test if the current event is an element tag with the given namespace and name.
     * If the namespace URI is null it is not checked for equality,
     * if the local name is null it is not checked for equality.
     * @param reader must not be {@code null}
     * @param event START_ELEMENT or END_ELEMENT
     * @param uri the namespace URI of the element, may be null
     * @param name the local name of the element, may be null
     * @return true if the required values are matched, false otherwise
     */
    private static boolean isElement(XMLStreamReader reader, int event, String uri, String name) {
        if (reader.getEventType() != event)
            return false;

        if (uri != null) {
            String found = reader.getNamespaceURI();
            if (!found.equals(uri))
                return false;
        }

        if (name != null) {
            String found = reader.getLocalName();
            if (!found.equals(name))
                return false;
        }

        return true;
    }
}