public interface InfosetReader
extends java.lang.Cloneable
The InfosetReader is designed to iterate over XML using next() and hasNext(). The data can be accessed using methods such as getEventType(), getQName(), getLocalName() and getData(), etc.
The next() method causes the reader to read the next event.
The event type can be determined using getEventType(). The events used are same as defined in JSR-173 (StAX API).
The following table describes which methods are valid in what state. If a method is called in an invalid state the method will throw a java.lang.IllegalStateException.
The parser has two optional features
Valid methods for each state | |
---|---|
Event Type | Valid Methods |
All States | getEventType(), hasNext(), next(), skip(), getOffset(), seek(), getNamespaceURI(), getPrefix() |
START_ELEMENT | getQName(), getAttributes(), getAttribute() getTypeName(), getPrimitiveTypeId(), isGlobal(), isNillable() |
ATTRIBUTE | getQName(), getTypeName(), getPrimitiveTypeId(), getData(), getDataLength(), getDataStart(), getValue() Only occurs when element-less attributes are present, possibly to represent XPath data model. |
NAMESPACE | NONE - doesn't occur. |
END_ELEMENT | getQName() |
CHARACTERS, CDATA, SPACE | getData(), getDataLength(), getDataStart(), getValue() |
COMMENT | getData(), getDataLength(), getDataStart(), getValue() |
START_DOCUMENT | getEncoding(), getVersion(), getStandalone(), getDoctype() |
END_DOCUMENT | close() |
PROCESSING_INSTRUCTION | getQName(), getData(), getDataLength(), getDataStart(), getValue() |
START_ENTITY, END_ENTITY, ENTITY_REFERENCE | getQName() |
DTD | NONE - doesn't occur |
Modifier and Type | Interface and Description |
---|---|
static interface |
InfosetReader.Offset
For opague object representing the current position/offset in the reader.
|
Modifier and Type | Field and Description |
---|---|
static int |
ATTRIBUTE
Indicates an event is an attribute
|
static int |
CDATA
Indicates an event is a CDATA section
|
static int |
CHARACTERS
Indicates an event is characters
|
static int |
COMMENT
Indicates an event is a comment
|
static int |
DTD
Indicates an event is a DTD
|
static int |
END_DOCUMENT
Indicates an event is an end document
|
static int |
END_ELEMENT
Indicates an event is an end element
|
static int |
END_ENTITY
Indicates an event is the end of a resolved entity
|
static int |
ENTITY_REFERENCE
Indicates an event is an entity reference
|
static int |
NAMESPACE
Indicates an event is a namepsace
|
static int |
PROCESSING_INSTRUCTION
Indicates an event is a processing instruction
|
static int |
SPACE
Indicates an event is a space, events are only reported as SPACE if they are ignorable white space.
|
static int |
START_DOCUMENT
Indicates an event is a start document
|
static int |
START_ELEMENT
Indicates an event is a start element
|
static int |
START_ENTITY
Indicates an event is the start of a resolved entity
|
Modifier and Type | Method and Description |
---|---|
java.lang.Object |
clone()
Clone the reader
|
void |
close()
Frees any resources associated with this InfosetReader.
|
java.lang.String |
getAttribute(javax.xml.namespace.QName attr)
Returns the attribute value of the current element with the given name Valid only if the current event is START_ELEMENT
|
char[] |
getData()
Return the data corresponding to the current event.
|
int |
getDataLength()
Returns the length of the sequence of characters for this event within the text character array.
|
int |
getDataStart()
Returns the offset into the text character array where the first character (of this text event) is stored.
|
DTD |
getDoctype()
Gets the DTD associated with the XML data.
|
java.lang.String |
getEncoding()
Get the xml encoding declared on the xml declaration Returns null if none was declared
|
int |
getEventFlags()
Get flags specific to the event
|
int |
getEventType()
Returns an integer code that indicates the type of the event the cursor is pointing to.
|
java.lang.String |
getNamespaceURI(java.lang.String prefix)
Get Namespace URI bound to a prefix in the current scope.
|
InfosetReader.Offset |
getOffset()
Returns an opaque object representing the current position/offset in the reader.
|
java.lang.String |
getPrefix(java.lang.String namespaceURI)
Get prefix bound to Namespace URI in the current scope.
|
int |
getPrimitiveTypeId()
Get the primitive type of the element This is valid at START_ELEMENT
|
javax.xml.namespace.QName |
getQName()
Get the name of the current event type This is valid at START_ELEMENT, END_ELEMENT, PROCESSING_INSTRUCTION, START_ENTITY, ENTITY_REFERENCE, END_ENTITY events
|
java.lang.String |
getStandalone()
Get the xml standalone declared on the xml declaration Returns null if none was declared
|
BinaryStream |
getStream()
Returns an opaque object representing the current binary stream
|
javax.xml.namespace.QName |
getTypeName()
Get the type name of the element.
|
java.lang.String |
getValue()
Return the data corresponding to the current event.
|
java.lang.String |
getVersion()
Get the xml version declared on the xml declaration Returns null if none was declared
|
boolean |
hasNext()
Returns true if there are more parsing events and false if there are no more events.
|
boolean |
isGlobal()
Is the current element based on global element decl?
|
boolean |
isNilled()
Is the element nillable?
|
boolean |
isNSResolutionSupported()
Checks if Namespace resolution supported
|
boolean |
isSeekSupported()
Checks if seek is supported
|
void |
next()
Get next parsing event This method will throw an IllegalStateException if it is called after hasNext() returns false.
|
InfosetReader.Offset |
offsetFromBytes(byte[] buf, int start)
Create offset from a byte representation in the byte buffer starting at 'start' index.
|
byte |
offsetToBytes(InfosetReader.Offset offset, byte[] buf, int start)
Write a byte representation of the Offset into the byte buffer starting at 'start' index.
|
long |
offsetToLong()
Returns a long representing the current position/offset in the reader.
|
void |
seek(InfosetReader.Offset offset)
Seek to a position in the reader represented by the Offset.
|
void |
seek(long offset)
Seek to a position in the reader represented by the long Offset.
|
void |
skip()
Skip this parsing event and the complete subtree This method has different behavior (as compared
next() ) only when the current event is START_DOCUMENT or START_ELEMENT The getEventType will return END_DOCUMENT or END_ELEMENT, skipping the content of the document or element This method will throw an IllegalStateException if it is called after hasNext() returns false. |
static final int START_ELEMENT
static final int END_ELEMENT
static final int PROCESSING_INSTRUCTION
static final int CHARACTERS
static final int COMMENT
static final int SPACE
static final int START_DOCUMENT
static final int END_DOCUMENT
static final int ENTITY_REFERENCE
static final int ATTRIBUTE
static final int DTD
static final int CDATA
static final int NAMESPACE
static final int START_ENTITY
static final int END_ENTITY
boolean isNSResolutionSupported()
java.lang.String getNamespaceURI(java.lang.String prefix)
Get Namespace URI bound to a prefix in the current scope.
prefix
- prefix to look upjava.lang.String getPrefix(java.lang.String namespaceURI)
Get prefix bound to Namespace URI in the current scope.
namespaceURI
- URI of Namespace to lookupboolean isSeekSupported()
BinaryStream getStream()
InfosetReader.Offset getOffset()
void seek(InfosetReader.Offset offset)
offset
- indicating amount to seeklong offsetToLong()
void seek(long offset)
long
- offset indicating amount to seekbyte offsetToBytes(InfosetReader.Offset offset, byte[] buf, int start)
offset
- - offset to be converted to bytesbuf
- - byte array to write intostart
- - start indexInfosetReader.Offset offsetFromBytes(byte[] buf, int start)
buf
- - byte array to read fromstart
- - start indexint getEventType()
boolean hasNext()
void next()
java.lang.IllegalStateException
- if this is called when hasNext() returns falsevoid skip()
next()
) only when the current event is START_DOCUMENT or START_ELEMENT The getEventType will return END_DOCUMENT or END_ELEMENT, skipping the content of the document or element This method will throw an IllegalStateException if it is called after hasNext() returns false.java.lang.IllegalStateException
- if this is called when hasNext() returns falsejava.lang.String getEncoding()
java.lang.String getVersion()
java.lang.String getStandalone()
DTD getDoctype()
javax.xml.namespace.QName getQName()
javax.xml.namespace.QName getTypeName()
int getPrimitiveTypeId()
boolean isGlobal()
boolean isNilled()
java.lang.String getAttribute(javax.xml.namespace.QName attr)
java.lang.String getValue()
char[] getData()
int getDataStart()
java.lang.IllegalStateException
- if this state is not a valid data state.int getDataLength()
java.lang.IllegalStateException
- if this state is not a valid data state.int getEventFlags()
void close()
java.lang.Object clone()