Interface XMLReader
-
- All Known Implementing Classes:
FastInfosetReader,LoggingXMLReader,RecordedXMLReader,StAXReader,XMLReaderBase,XMLReaderImpl,XmlTreeReader
public interface XMLReaderXMLReader provides a high-level streaming parser interface for reading XML documents.
The
next()method is used to read events from the XML document.Each time it is called,
next()returns the new state of the reader.Possible states are: BOF, the initial state, START, denoting the start tag of an element, END, denoting the end tag of an element, CHARS, denoting the character content of an element, PI, denoting a processing instruction, EOF, denoting the end of the document.
Depending on the state the reader is in, one or more of the following query methods will be meaningful:
getName(),getURI(),getLocalName(),getAttributes(),getValue().Elements visited by a XMLReader are tagged with unique IDs. The ID of the current element can be found by calling
getElementId().A XMLReader is always namespace-aware, and keeps track of the namespace declarations which are in scope at any time during streaming. The
getURI(java.lang.String)method can be used to find the URI associated to a given prefix in the current scope.XMLReaders can be created using a
XMLReaderFactory.Some utility methods,
nextContent()andnextElementContent()make it possible to ignore whitespace and processing instructions with minimum impact on the client code.Similarly, the
skipElement()andskipElement(int elementId)methods allow to skip to the end tag of an element ignoring all its content.Finally, the
recordElement()method can be invoked when the XMLReader is positioned on the start tag of an element to record the element's contents so that they can be played back later.- Author:
- JAX-RPC Development Team
- See Also:
XMLReaderFactory
-
-
Field Summary
Fields Modifier and Type Field Description static intBOFThe initial state of a XMLReader.static intCHARSThe state denoting the character content of an element.static intENDThe state denoting the end tag of an element.static intEOFThe state denoting that the end of the document has been reached.static intPIThe state denoting a processing instruction.static intSTARTThe state denoting the start tag of an element.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidclose()Close the XMLReader.AttributesgetAttributes()Return the current attribute list.intgetElementId()Return the current element ID.intgetLineNumber()Return the current line number.StringgetLocalName()Return the current local name.QNamegetName()Return the current qualified name.IteratorgetPrefixes()Return an iterator on all prefixes in scope, except for the default prefix.intgetState()Return the current state of the XMLReader.StringgetURI()Return the current URI.StringgetURI(String prefix)Return the URI for the given prefix.StringgetValue()Return the current value.intnext()Return the next state of the XMLReader.intnextContent()intnextElementContent()Return the next state of the XMLReader.XMLReaderrecordElement()Records the current element and leaves the reader positioned on its end tag.voidskipElement()Skip all nodes up to the end tag of the element with the current element ID.voidskipElement(int elementId)Skip all nodes up to the end tag of the element with the given element ID.
-
-
-
Field Detail
-
BOF
static final int BOF
The initial state of a XMLReader.- See Also:
- Constant Field Values
-
START
static final int START
The state denoting the start tag of an element.- See Also:
- Constant Field Values
-
END
static final int END
The state denoting the end tag of an element.- See Also:
- Constant Field Values
-
CHARS
static final int CHARS
The state denoting the character content of an element.- See Also:
- Constant Field Values
-
PI
static final int PI
The state denoting a processing instruction.- See Also:
- Constant Field Values
-
EOF
static final int EOF
The state denoting that the end of the document has been reached.- See Also:
- Constant Field Values
-
-
Method Detail
-
next
int next()
Return the next state of the XMLReader. The return value is one of: START, END, CHARS, PI, EOF.
-
nextContent
int nextContent()
-
nextElementContent
int nextElementContent()
Return the next state of the XMLReader.Whitespace character content, processing instructions are ignored. Non-whitespace character content triggers an exception.
The return value is one of: START, END, EOF.
-
getState
int getState()
Return the current state of the XMLReader.
-
getName
QName getName()
Return the current qualified name.Meaningful only when the state is one of: START, END.
-
getURI
String getURI()
Return the current URI.Meaningful only when the state is one of: START, END.
-
getLocalName
String getLocalName()
Return the current local name.Meaningful only when the state is one of: START, END, PI.
-
getAttributes
Attributes getAttributes()
Return the current attribute list.Meaningful only when the state is one of: START.
The returned
Attributesobject belong to the XMLReader and is only guaranteed to be valid until thenext()method is called, directly or indirectly.
-
getValue
String getValue()
Return the current value.Meaningful only when the state is one of: CHARS, PI.
-
getElementId
int getElementId()
Return the current element ID.
-
getLineNumber
int getLineNumber()
Return the current line number.Due to aggressive parsing, this value may be off by a few lines.
-
getURI
String getURI(String prefix)
Return the URI for the given prefix.If there is no namespace declaration in scope for the given prefix, return null.
-
getPrefixes
Iterator getPrefixes()
Return an iterator on all prefixes in scope, except for the default prefix.
-
recordElement
XMLReader recordElement()
Records the current element and leaves the reader positioned on its end tag.The XMLReader must be positioned on the start tag of the element. The returned reader will play back all events starting with the start tag of the element and ending with its end tag.
-
skipElement
void skipElement()
Skip all nodes up to the end tag of the element with the current element ID.
-
skipElement
void skipElement(int elementId)
Skip all nodes up to the end tag of the element with the given element ID.
-
close
void close()
Close the XMLReader.All subsequent calls to
next()will return EOF.
-
-