Java tutorial
//package com.java2s; /******************************************************************************* * Copyright (c) 2006-2010 eBay Inc. All Rights Reserved. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 *******************************************************************************/ import javax.xml.stream.XMLStreamConstants; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamReader; public class Main { /** * Advance the reader to the next end element and return true. Return false if next end element is not found * @param reader a XMLStreamReader * @return True when successfully advanced the reader. * @throws XMLStreamException Exception when reading from the XMLStreamReader fails. */ public static boolean advanceToNextEndElement(XMLStreamReader reader) throws XMLStreamException { while (reader.getEventType() != XMLStreamConstants.END_ELEMENT) { if (reader.hasNext()) { reader.next(); } else { // reach the end of elements in reader. Not found. return false; } } return true; } }