XMLReader provides a high-level streaming parser interface
for reading XML documents.
The
XMLReader.next method is used to read events from the XML document.
Each time it is called,
XMLReader.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:
XMLReader.getName ,
XMLReader.getURI ,
XMLReader.getLocalName ,
XMLReader.getAttributes ,
XMLReader.getValue .
Elements visited by a XMLReader are tagged with unique IDs. The ID of the
current element can be found by calling
XMLReader.getElementId .
A XMLReader is always namespace-aware, and keeps track of the namespace
declarations which are in scope at any time during streaming. The
XMLReader.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,
XMLReader.nextContent and
XMLReader.nextElementContent make it possible to ignore whitespace and processing instructions with
minimum impact on the client code.
Similarly, the
XMLReader.skipElement and
XMLReader.skipElement(int elementId) methods allow to skip to the end tag of an element ignoring all its content.
Finally, the
XMLReader.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.
See Also: XMLReaderFactory author: WS Development Team |