Java tutorial
//package com.java2s; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamReader; public class Main { /** * 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 * @param slash "" or "/", for error message * @throws XMLStreamException if the required values are not matched. */ private static void requireElement(XMLStreamReader reader, int event, String uri, String name, String slash) throws XMLStreamException { // Note: reader.require(event, uri, name) has a lousy error message if (reader.getEventType() != event) throw new XMLStreamException("expected <" + slash + name + ">", reader.getLocation()); if (uri != null) { String found = reader.getNamespaceURI(); if (!found.equals(uri)) throw new XMLStreamException( "expected <" + slash + name + "> with namespace [" + uri + "], found [" + found + "]", reader.getLocation()); } if (name != null) { String found = reader.getLocalName(); if (!found.equals(name)) throw new XMLStreamException("expected <" + slash + name + ">, found <" + slash + found + ">", reader.getLocation()); } } }