Path: blob/master/src/java.xml/share/classes/javax/xml/stream/XMLEventReader.java
40948 views
/*1* Copyright (c) 2009, 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.xml.stream;2627import javax.xml.stream.events.XMLEvent;2829import java.util.Iterator;3031/**32*33* This is the top level interface for parsing XML Events. It provides34* the ability to peek at the next event and returns configuration35* information through the property interface.36*37* @version 1.038* @author Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.39* @see XMLInputFactory40* @see XMLEventWriter41* @since 1.642*/43public interface XMLEventReader extends Iterator<Object> {44/**45* Gets the next XMLEvent. The initial event is46* {@link javax.xml.stream.events.StartDocument StartDocument}.47*48* @return the next XMLEvent49* @see XMLEvent50* @throws XMLStreamException if there is an error with the underlying XML.51* @throws java.util.NoSuchElementException iteration has no more elements.52*/53public XMLEvent nextEvent() throws XMLStreamException;5455/**56* Check if there are more events.57* Returns true if there are more events and false otherwise.58* @return true if the event reader has more events, false otherwise59*/60@Override61public boolean hasNext();6263/**64* Check the next XMLEvent without reading it from the stream.65* Returns null if the stream is at EOF or has no more XMLEvents.66* A call to peek() will be equal to the next return of next().67*68* @return the next XMLEvent69* @see XMLEvent70* @throws XMLStreamException if an error occurs71*/72public XMLEvent peek() throws XMLStreamException;7374/**75* Reads the content of a text-only element. Precondition:76* the current event is START_ELEMENT. Postcondition:77* The current event is the corresponding END_ELEMENT.78*79* @return the text of the element80* @throws XMLStreamException if the current event is not a START_ELEMENT81* or if a non text element is encountered82*/83public String getElementText() throws XMLStreamException;8485/**86* Skips any insignificant space events until a START_ELEMENT or87* END_ELEMENT is reached. If anything other than space characters are88* encountered, an exception is thrown. This method should89* be used when processing element-only content because90* the parser is not able to recognize ignorable whitespace if91* the DTD is missing or not interpreted.92*93* @return a START_ELEMENT or END_ELEMENT94* @throws XMLStreamException if anything other than space characters are encountered95*/96public XMLEvent nextTag() throws XMLStreamException;9798/**99* Get the value of a feature/property from the underlying implementation100* @param name The name of the property101* @return The value of the property102* @throws IllegalArgumentException if the property is not supported103*/104public Object getProperty(java.lang.String name) throws java.lang.IllegalArgumentException;105106/**107* Frees any resources associated with this Reader. This method does not close the108* underlying input source.109* @throws XMLStreamException if there are errors freeing associated resources110*/111public void close() throws XMLStreamException;112}113114115