public interface TypedXMLStreamReader extends XMLStreamReader
XMLStreamReader
. It defines methods for
reading XML data and converting it into Java types.ATTRIBUTE, CDATA, CHARACTERS, COMMENT, DTD, END_DOCUMENT, END_ELEMENT, ENTITY_DECLARATION, ENTITY_REFERENCE, NAMESPACE, NOTATION_DECLARATION, PROCESSING_INSTRUCTION, SPACE, START_DOCUMENT, START_ELEMENT
Modifier and Type | Method and Description |
---|---|
void |
getAttributeAs(int index,
TypedValueDecoder tvd)
Generic access method that can be used for efficient
decoding of additional types not support natively
by the typed stream reader.
|
int |
getAttributeAsArray(int index,
TypedArrayDecoder tad)
Method that allows reading contents of an attribute as an array
of whitespace-separate tokens, decoded using specified decoder.
|
byte[] |
getAttributeAsBinary(int index)
Read an attribute value as a byte array.
|
byte[] |
getAttributeAsBinary(int index,
Base64Variant v) |
boolean |
getAttributeAsBoolean(int index)
Read an attribute value as a boolean.
|
BigDecimal |
getAttributeAsDecimal(int index) |
double |
getAttributeAsDouble(int index) |
double[] |
getAttributeAsDoubleArray(int index) |
float |
getAttributeAsFloat(int index) |
float[] |
getAttributeAsFloatArray(int index) |
int |
getAttributeAsInt(int index)
Read an attribute value as a boolean.
|
int[] |
getAttributeAsIntArray(int index)
Read an attribute content as an int array.
|
BigInteger |
getAttributeAsInteger(int index) |
long |
getAttributeAsLong(int index)
Read an attribute value as a boolean.
|
long[] |
getAttributeAsLongArray(int index) |
QName |
getAttributeAsQName(int index) |
int |
getAttributeIndex(String namespaceURI,
String localName)
Returns the index of the attribute whose local name is
localName and URI is namespaceURI
or -1 if no such attribute exists. |
void |
getElementAs(TypedValueDecoder tvd)
Generic decoding method that can be used for efficient
decoding of additional types not support natively
by the typed stream reader.
|
byte[] |
getElementAsBinary()
Convenience method that can be used similar to read binary content
instead of
readElementAsBinary(byte[], int, int, org.codehaus.stax2.typed.Base64Variant) , in cases where neither performance nor
memory usage is a big concern. |
byte[] |
getElementAsBinary(Base64Variant variant)
Convenience method that can be used similar to read binary content
instead of
readElementAsBinary(byte[], int, int, org.codehaus.stax2.typed.Base64Variant) , in cases where neither performance nor
memory usage is a big concern. |
boolean |
getElementAsBoolean()
Read an element content as a boolean.
|
BigDecimal |
getElementAsDecimal() |
double |
getElementAsDouble()
Read an element content as a 64-bit floating point value.
|
float |
getElementAsFloat()
Read an element content as a 32-bit floating point value.
|
int |
getElementAsInt()
Read an element content as a 32-bit integer.
|
BigInteger |
getElementAsInteger() |
long |
getElementAsLong()
Read an element content as a 64-bit integer.
|
QName |
getElementAsQName() |
int |
readElementAsArray(TypedArrayDecoder tad)
Read an element content as an array of tokens.
|
int |
readElementAsBinary(byte[] resultBuffer,
int offset,
int maxLength) |
int |
readElementAsBinary(byte[] resultBuffer,
int offset,
int maxLength,
Base64Variant variant)
Read element content as decoded byte sequence; possibly only
reading a fragment of all element content.
|
int |
readElementAsDoubleArray(double[] resultBuffer,
int offset,
int length) |
int |
readElementAsFloatArray(float[] resultBuffer,
int offset,
int length) |
int |
readElementAsIntArray(int[] resultBuffer,
int offset,
int length)
Read an element content as an int array.
|
int |
readElementAsLongArray(long[] resultBuffer,
int offset,
int length) |
close, getAttributeCount, getAttributeLocalName, getAttributeName, getAttributeNamespace, getAttributePrefix, getAttributeType, getAttributeValue, getAttributeValue, getCharacterEncodingScheme, getElementText, getEncoding, getEventType, getLocalName, getLocation, getName, getNamespaceContext, getNamespaceCount, getNamespacePrefix, getNamespaceURI, getNamespaceURI, getNamespaceURI, getPIData, getPITarget, getPrefix, getProperty, getText, getTextCharacters, getTextCharacters, getTextLength, getTextStart, getVersion, hasName, hasNext, hasText, isAttributeSpecified, isCharacters, isEndElement, isStandalone, isStartElement, isWhiteSpace, next, nextTag, require, standaloneSet
boolean getElementAsBoolean() throws XMLStreamException
Read an element content as a boolean. The lexical representation of a boolean is defined by the XML Schema boolean data type. Whitespace MUST be collapsed according to the whiteSpace facet for the XML Schema boolean data type. An exception is thrown if, after whitespace is collapsed, the resulting sequence of characters is not in the lexical space defined by the XML Schema boolean data type. (note: allowed lexical values are canonicals "true" and "false", as well as non-canonical "0" and "1")
These are the pre- and post-conditions of calling this method:
XMLStreamException
- If unable to access contentTypedXMLStreamException
- If unable to convert the resulting
character sequence into an XML Schema boolean value.int getElementAsInt() throws XMLStreamException
Read an element content as a 32-bit integer. The lexical representation of a integer is defined by the XML Schema integer data type. Whitespace MUST be collapsed according to the whiteSpace facet for the XML Schema integer data type. An exception is thrown if, after whitespace is collapsed, the resulting sequence of characters is not in the lexical space defined by the XML Schema integer data type.
These are the pre and post conditions of calling this method:
XMLStreamException
- If unable to access contentTypedXMLStreamException
- If unable to convert the resulting
character sequence into a Java (32-bit) integer.long getElementAsLong() throws XMLStreamException
Read an element content as a 64-bit integer. The lexical representation of a integer is defined by the XML Schema integer data type. Whitespace MUST be collapsed according to the whiteSpace facet for the XML Schema integer data type. An exception is thrown if, after whitespace is collapsed, the resulting sequence of characters is not in the lexical space defined by the XML Schema integer data type.
These are the pre and post conditions of calling this method:
XMLStreamException
- If unable to access contentTypedXMLStreamException
- If unable to convert the resulting
character sequence into a Java (64-bit) integer.float getElementAsFloat() throws XMLStreamException
Read an element content as a 32-bit floating point value.
The lexical representation is defined by the
XML Schema float data type. Whitespace MUST be
collapsed
according to the whiteSpace facet for the XML Schema float data type.
An exception is thrown if, after whitespace is
collapsed, the resulting sequence of characters is not in
the lexical space defined by the XML Schema integer data type.
Note that valid representations include basic Java textual
representations, as well as 3 special tokens: "INF", "-INF"
and "NaN"
These are the pre and post conditions of calling this method:
XMLStreamException
- If unable to access contentTypedXMLStreamException
- If unable to convert the resulting
character sequence into a Java floatdouble getElementAsDouble() throws XMLStreamException
Read an element content as a 64-bit floating point value.
The lexical representation is defined by the
XML Schema double data type. Whitespace MUST be
collapsed
according to the whiteSpace facet for the XML Schema double data type.
An exception is thrown if, after whitespace is
collapsed, the resulting sequence of characters is not in
the lexical space defined by the XML Schema integer data type.
Note that valid representations include basic Java textual
representations, as well as 3 special tokens: "INF", "-INF"
and "NaN"
These are the pre and post conditions of calling this method:
XMLStreamException
- If unable to access contentTypedXMLStreamException
- If unable to convert the resulting
character sequence into a Java doubleBigInteger getElementAsInteger() throws XMLStreamException
XMLStreamException
BigDecimal getElementAsDecimal() throws XMLStreamException
XMLStreamException
QName getElementAsQName() throws XMLStreamException
XMLStreamException
byte[] getElementAsBinary() throws XMLStreamException
readElementAsBinary(byte[], int, int, org.codehaus.stax2.typed.Base64Variant)
, in cases where neither performance nor
memory usage is a big concern.
Note: base64 variant defaults to Base64Variants.MIME
.
byte[] getElementAsBinary(Base64Variant variant) throws XMLStreamException
readElementAsBinary(byte[], int, int, org.codehaus.stax2.typed.Base64Variant)
, in cases where neither performance nor
memory usage is a big concern.variant
- Base64 variant content is in; needed to decode
alternative variants ("modified base64")XMLStreamException
readElementAsBinary(byte[], int, int, org.codehaus.stax2.typed.Base64Variant)
void getElementAs(TypedValueDecoder tvd) throws XMLStreamException
XMLStreamReader.getElementText()
,
and then call one of decode methods defined in
TypedValueDecoder
. The only difference is that
passed value will be trimmed: that is, any leading or
trailing white space will be removed prior to calling
decode method.
After the call, passed
decoder object will have decoded and stored value
(if succesful) or thrown an exception (if not).
The main benefit of using this method (over just getting
all content by calling XMLStreamReader.getElementText()
is efficiency: the stream reader can efficiently gather all textual
content necessary and pass it to the decoder, often avoiding
construction of intemediate Strings.
These are the pre- and post-conditions of calling this method:
Note that caller has to know more specific type of decoder, since the base interface does not specify methods for accessing actual decoded value.
XMLStreamException
int readElementAsBinary(byte[] resultBuffer, int offset, int maxLength, Base64Variant variant) throws XMLStreamException
Each call will read at least one decoded byte (and no more than the specified maximum length), if there is any content remaining. If none is available and END_ELEMENT is encountered, -1 is returned.
These are the pre and post conditions of calling this method:
Additionally, caller MUST start decoding at START_ELEMENT; if the first decode calls is at CHARACTERS or CDATA event, results are not defined: result may be an exception, or invalid data being returned. Implementations are encouraged to throw an exception if possible, to make it easier to figure out the problem.
This method can be called multiple times until the cursor is positioned at the corresponding END_ELEMENT event. Stated differently, after the method is called for the first time, the cursor will move and remain in the CHARACTERS position while there are potentially more bytes available for reading.
resultBuffer
- Array in which to copy decoded bytes.offset
- Starting offset of the first decoded byte
within result buffermaxLength
- Maximun number of bytes to decode with this callmaxLength
Note that this value is not guaranteed to equal maxLength
even if enough content was available; that is, implementations
can return shorter sections if they choose to, down to and including
returning zero (0) if it was not possible to decode a full base64
triplet (3 output bytes from 4 input characters).IllegalArgumentException
- If resultBuffer
is
null or offset is less than 0.XMLStreamException
int readElementAsBinary(byte[] resultBuffer, int offset, int maxLength) throws XMLStreamException
XMLStreamException
int readElementAsIntArray(int[] resultBuffer, int offset, int length) throws XMLStreamException
<xs:simpleType name="intArray"> <xs:list itemType="xs:int"/> </xs:simpleType>whose lexical space is a list of space-separated ints. Whitespace MUST be collapsed according to the whiteSpace facet for the
intArray
type shown above. An exception is thrown if, after whitespace is
collapsed, the resulting sequence of characters is not in
the lexical space defined by the intArray
data
type.
These are the pre and post conditions of calling this method:
resultBuffer
- The array in which to copy the ints.offset
- The index in the array from which copying starts.length
- The maximun number of ints to copy. Minimum value
is 1; others an IllegalArgumentException
is thrownlength
, but
at least one if any ints found. If not, -1 is returned
to signal end of ints to parse.IllegalStateException
- If called on event other than
START_ELEMENT, END_ELEMENT, or CHARACTERS (which resulted from
an earlier call)XMLStreamException
int readElementAsLongArray(long[] resultBuffer, int offset, int length) throws XMLStreamException
XMLStreamException
int readElementAsFloatArray(float[] resultBuffer, int offset, int length) throws XMLStreamException
XMLStreamException
int readElementAsDoubleArray(double[] resultBuffer, int offset, int length) throws XMLStreamException
XMLStreamException
int readElementAsArray(TypedArrayDecoder tad) throws XMLStreamException
These are the pre- and post-conditions of calling this method:
Note: passed decoder must accept at least one value, reader will not verify capacity before calling it with the first token.
IllegalStateException
- If called on event other than
START_ELEMENT, END_ELEMENT, or CHARACTERS (which resulted from
an earlier call)XMLStreamException
int getAttributeIndex(String namespaceURI, String localName)
localName
and URI is namespaceURI
or -1
if no such attribute exists.namespaceURI
- The attribute's namespace URI. Values of
null and "" are considered the same, i.e. "no namespace"
(or "empty" namespace)localName
- The attribute's local name.-1
if no
such attribute exists.IllegalStateException
- If this is not
a START_ELEMENT eventXMLStreamException
- If unable to convert the resulting
character sequence into an XML Schema boolean value.boolean getAttributeAsBoolean(int index) throws XMLStreamException
Read an attribute value as a boolean. The lexical representation of a boolean is defined by the XML Schema boolean data type. Whitespace MUST be collapsed according to the whiteSpace facet for the XML Schema boolean data type. An exception is thrown if, after whitespace is collapsed, the resulting sequence of characters is not in the lexical space defined by the XML Schema boolean data type.
index
- The attribute's index as returned by getAttributeIndex(String, String)
IllegalStateException
- If this is not
a START_ELEMENT event.XMLStreamException
- If unable to convert the resulting
character sequence into an XML Schema boolean value.int getAttributeAsInt(int index) throws XMLStreamException
Read an attribute value as a boolean. The lexical representation of a boolean is defined by the XML Schema integer data type. Whitespace MUST be collapsed according to the whiteSpace facet for the type. An exception is thrown if, after whitespace is collapsed, the resulting sequence of characters is not in the lexical space defined by the XML Schema integer data type.
index
- The attribute's index as returned by getAttributeIndex(String, String)
IllegalStateException
- If this is not a START_ELEMENT event.XMLStreamException
- If unable to convert the resulting
character sequence into an XML Schema boolean value.long getAttributeAsLong(int index) throws XMLStreamException
Read an attribute value as a boolean. The lexical representation of a boolean is defined by the XML Schema long data type. Whitespace MUST be collapsed according to the whiteSpace facet for the type. An exception is thrown if, after whitespace is collapsed, the resulting sequence of characters is not in the lexical space defined by the XML Schema long data type.
index
- The attribute's index as returned by getAttributeIndex(String, String)
IllegalStateException
- If this is not a START_ELEMENT event.XMLStreamException
- If unable to convert the resulting
character sequence into an XML Schema boolean value.float getAttributeAsFloat(int index) throws XMLStreamException
XMLStreamException
double getAttributeAsDouble(int index) throws XMLStreamException
XMLStreamException
BigInteger getAttributeAsInteger(int index) throws XMLStreamException
XMLStreamException
BigDecimal getAttributeAsDecimal(int index) throws XMLStreamException
XMLStreamException
QName getAttributeAsQName(int index) throws XMLStreamException
XMLStreamException
void getAttributeAs(int index, TypedValueDecoder tvd) throws XMLStreamException
As with getElementAs(org.codehaus.stax2.typed.TypedValueDecoder)
, value passed to a decode
method will be trimmed of any leading or trailing white space.
XMLStreamException
byte[] getAttributeAsBinary(int index) throws XMLStreamException
index
- The attribute's index as returned by getAttributeIndex(String, String)
.IllegalStateException
- If this is not
a START_ELEMENT or ATTRIBUTE event.XMLStreamException
- If unable to convert the resulting
character sequence into an XML Schema boolean value.byte[] getAttributeAsBinary(int index, Base64Variant v) throws XMLStreamException
XMLStreamException
int[] getAttributeAsIntArray(int index) throws XMLStreamException
Read an attribute content as an int array. The lexical representation of a int array is defined by the following XML schema type:
<xs:simpleType name="intArray"> <xs:list itemType="xs:int"/> </xs:simpleType>whose lexical space is a list of space-separated ints. Whitespace MUST be collapsed according to the whiteSpace facet for the
intArray
type shown above. An exception is thrown if, after whitespace is
collapsed, the resulting sequence of characters is not in
the lexical space defined by the intArray
data
type.index
- The attribute's index as returned by getAttributeIndex(String, String)
.IllegalStateException
- If this is not
a START_ELEMENT or ATTRIBUTE event.XMLStreamException
- If unable to convert the resulting
character sequence into an XML Schema boolean value.long[] getAttributeAsLongArray(int index) throws XMLStreamException
XMLStreamException
float[] getAttributeAsFloatArray(int index) throws XMLStreamException
XMLStreamException
double[] getAttributeAsDoubleArray(int index) throws XMLStreamException
XMLStreamException
int getAttributeAsArray(int index, TypedArrayDecoder tad) throws XMLStreamException
XMLStreamException
Copyright © 2012-2015 fasterxml.com. All Rights Reserved.