Package org.dellroad.stuff.xml
Class StackXMLEventReader
java.lang.Object
javax.xml.stream.util.EventReaderDelegate
org.dellroad.stuff.xml.StackXMLEventReader
- All Implemented Interfaces:
Iterator<Object>,XMLEventReader
Wrapper for a
XMLEventReader that keeps track of the current element(s) being parsed as a stack
of StartElement events.
Each time a StartElement is read from the underlying XMLEventReader, it is pushed onto
the stack; each time a EndElement is read from the underlying XMLEventReader,
the previously push StartElement is popped off.
Invocations of EventReaderDelegate.peek() do not affect the element stack.
If an XMLStreamException is thrown at any point, the element stack is no longer guaranteed to track properly.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected XMLEventAdjust the stack after reading the given event.Get the entire stack ofStartElements.Get the top-mostStartElementevent on the stack.next()nextTag()Methods inherited from class javax.xml.stream.util.EventReaderDelegate
close, getParent, getProperty, hasNext, peek, remove, setParentMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.Iterator
forEachRemaining
-
Constructor Details
-
StackXMLEventReader
Constructor.- Parameters:
reader- underlying reader- Throws:
IllegalArgumentException- ifreaderis null
-
-
Method Details
-
getTopElement
Get the top-mostStartElementevent on the stack. This corresponds to the innermost XML element currently being read.- Returns:
- current element, or null if the current parse position is outside of the document element
-
getElementStack
Get the entire stack ofStartElements.A copy is returned; changes to the returned list do not affect this instance.
- Returns:
- element stack; the first element in the list is the document element
-
getElementText
- Specified by:
getElementTextin interfaceXMLEventReader- Overrides:
getElementTextin classEventReaderDelegate- Throws:
XMLStreamException
-
next
- Specified by:
nextin interfaceIterator<Object>- Overrides:
nextin classEventReaderDelegate
-
nextEvent
- Specified by:
nextEventin interfaceXMLEventReader- Overrides:
nextEventin classEventReaderDelegate- Throws:
XMLStreamException
-
nextTag
- Specified by:
nextTagin interfaceXMLEventReader- Overrides:
nextTagin classEventReaderDelegate- Throws:
XMLStreamException
-
adjust
Adjust the stack after reading the given event.- Parameters:
event- newly read event- Returns:
event
-