Java tutorial
//package com.java2s; //License from project: Open Source License import javax.xml.stream.XMLStreamConstants; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamReader; public class Main { public static void consumeEnd(XMLStreamReader xmlRdr, String elementName) throws XMLStreamException { while (xmlRdr.hasNext()) { if (xmlRdr.isEndElement() && xmlRdr.getLocalName().equals(elementName)) { xmlRdr.next(); return; } xmlRdr.next(); } throw new IllegalStateException( "expected start tag <" + elementName + ">, found '" + xmlRdr.getText() + "'"); } public static boolean isEndElement(XMLStreamReader xmlRdr, String tagName) { return isElement(xmlRdr, XMLStreamConstants.END_ELEMENT, tagName); } public static boolean isElement(XMLStreamReader xmlRdr, int eventType, String tagName) { int event = xmlRdr.getEventType(); if (event == eventType) { String locName = xmlRdr.getLocalName(); if (locName.equals(tagName)) return true; } return false; } }