Java tutorial
//package com.java2s; import static javax.xml.stream.XMLStreamConstants.*; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamReader; public class Main { /** * Skip current element, including all its content. * Precondition: the current event is START_ELEMENT. * Postcondition: the current event is the corresponding END_ELEMENT. * Similar to {@link XMLStreamReader#nextTag()}, but also skips text content. * @param reader must not be {@code null} * @throws XMLStreamException if the current event is not START_ELEMENT or there is an error processing the underlying XML source */ public static void skipElement(XMLStreamReader reader) throws XMLStreamException { if (reader.getEventType() != START_ELEMENT) throw new XMLStreamException("expected start of element", reader.getLocation()); int depth = 0; while (reader.hasNext()) { int event = reader.next(); if (event == START_ELEMENT) { ++depth; } else if (event == END_ELEMENT) { --depth; if (depth == -1) break; } } } }