Java tutorial
//package com.java2s; import javax.xml.stream.events.StartElement; import javax.xml.stream.events.XMLEvent; public class Main { public static StartElement assertStart(String name, XMLEvent event) { if (!isTag(event, name)) { throw new RuntimeException("Was expecting a " + name + " tag, not this:" + event); } return event.asStartElement(); } /** * @param e * @param localName * @return true if the given XML event is a start tag named localName. */ public static boolean isTag(XMLEvent e, String localName) { return e.isStartElement() && localNameOf(e).equals(localName); } public static String localNameOf(XMLEvent e) { if (e.isStartElement()) { return e.asStartElement().getName().getLocalPart(); } else if (e.isEndElement()) { return e.asEndElement().getName().getLocalPart(); } throw new RuntimeException(e + " isn't a tag to get the name of."); } }