Wiki source for FunctionStAXhasNext
=====Function hasNext=====
This function is part of the [[FunctionsStAX StAX]] support.
====Name====
**hasNext** returns true if the ""StAX"" stream has a pending next event (optionally of the requested type and name).
====Synopsis====
hasNext( $reader )
hasNext( $reader type )
hasNext( $reader type name )
====Description====
hasNext has 3 forms. Each returns true if there is a (matching) next event and false if at EOF (with no matching next event).
Unlike the Java ""XMLEventReader"" method of the same name, hasNext advances the stream to the matching event (or EOF if no match).
This allows a significantly simplier and more efficient implemenation when processing a subset of event types and names.
The first argument must be an ""XMLEventReader"" created from the [[FunctionStAXnewEventReader newEventReader]] function.
If a second argument is present it must be one of the "XMLEvent" types (as a string)
- START_ELEMENT
- END_ELEMENT
- PROCESSING_INSTRUCTION
- CHARACTERS
- COMMENT
- SPACE
- START_DOCUMENT
- END_DOCUMENT
- ENTITY_REFERENCE
- DTD
- CDATA
- NAMESPACE
- NOTATION_DECLARATION
- ENTITY_DECLARATION
(Note that ATTRIBUTE events will not occur in the input stream, they are contained within START_ELEMENT events).
If a third argument is present and only if the event type is START_ELEMENT or END_ELEMENT then the argument is interpreted as a [[FunctionQName QName]] and hasNext advances until a matching START_ELEMENT or END_ELEMENT event is found.
To use the ""StAX"" functions you need to [[CommandImport import]] them into either the global namespace or a local namespace.
Its recommended that you use a local namespace so that there is less chance of name collisions.
Example: process every START_EVENT for element named "element"
%%
import commands stax=stax
reader=stax:newEventReader( file.xml )
while [ stax:hasNext( $reader START_ELEMENT element ) ] ; do
event=stax:nextEvent( $reader ) ;
done
stax:closeReader $reader
%%
----
[[Commands]]
[[FunctionsStAX StAX Functions]]
[[FunctionStAXnewEventReader newEventReader]]
[[FunctionStAXnextEvent nextEvent]]
[[JavaObjects Java Objects]]
This function is part of the [[FunctionsStAX StAX]] support.
====Name====
**hasNext** returns true if the ""StAX"" stream has a pending next event (optionally of the requested type and name).
====Synopsis====
hasNext( $reader )
hasNext( $reader type )
hasNext( $reader type name )
====Description====
hasNext has 3 forms. Each returns true if there is a (matching) next event and false if at EOF (with no matching next event).
Unlike the Java ""XMLEventReader"" method of the same name, hasNext advances the stream to the matching event (or EOF if no match).
This allows a significantly simplier and more efficient implemenation when processing a subset of event types and names.
The first argument must be an ""XMLEventReader"" created from the [[FunctionStAXnewEventReader newEventReader]] function.
If a second argument is present it must be one of the "XMLEvent" types (as a string)
- START_ELEMENT
- END_ELEMENT
- PROCESSING_INSTRUCTION
- CHARACTERS
- COMMENT
- SPACE
- START_DOCUMENT
- END_DOCUMENT
- ENTITY_REFERENCE
- DTD
- CDATA
- NAMESPACE
- NOTATION_DECLARATION
- ENTITY_DECLARATION
(Note that ATTRIBUTE events will not occur in the input stream, they are contained within START_ELEMENT events).
If a third argument is present and only if the event type is START_ELEMENT or END_ELEMENT then the argument is interpreted as a [[FunctionQName QName]] and hasNext advances until a matching START_ELEMENT or END_ELEMENT event is found.
To use the ""StAX"" functions you need to [[CommandImport import]] them into either the global namespace or a local namespace.
Its recommended that you use a local namespace so that there is less chance of name collisions.
Example: process every START_EVENT for element named "element"
%%
import commands stax=stax
reader=stax:newEventReader( file.xml )
while [ stax:hasNext( $reader START_ELEMENT element ) ] ; do
event=stax:nextEvent( $reader ) ;
done
stax:closeReader $reader
%%
----
[[Commands]]
[[FunctionsStAX StAX Functions]]
[[FunctionStAXnewEventReader newEventReader]]
[[FunctionStAXnextEvent nextEvent]]
[[JavaObjects Java Objects]]