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
-
Method Summary
Modifier and TypeMethodDescriptionprotected XMLEvent
Adjust the stack after reading the given event.Get the entire stack ofStartElement
s.Get the top-mostStartElement
event on the stack.next()
nextTag()
Methods inherited from class javax.xml.stream.util.EventReaderDelegate
close, getParent, getProperty, hasNext, peek, remove, setParent
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.util.Iterator
forEachRemaining
-
Constructor Details
-
StackXMLEventReader
Constructor.- Parameters:
reader
- underlying reader- Throws:
IllegalArgumentException
- ifreader
is null
-
-
Method Details
-
getTopElement
Get the top-mostStartElement
event 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 ofStartElement
s.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:
getElementText
in interfaceXMLEventReader
- Overrides:
getElementText
in classEventReaderDelegate
- Throws:
XMLStreamException
-
next
- Specified by:
next
in interfaceIterator<Object>
- Overrides:
next
in classEventReaderDelegate
-
nextEvent
- Specified by:
nextEvent
in interfaceXMLEventReader
- Overrides:
nextEvent
in classEventReaderDelegate
- Throws:
XMLStreamException
-
nextTag
- Specified by:
nextTag
in interfaceXMLEventReader
- Overrides:
nextTag
in classEventReaderDelegate
- Throws:
XMLStreamException
-
adjust
Adjust the stack after reading the given event.- Parameters:
event
- newly read event- Returns:
event
-