Name
ParserAdapter
Synopsis
This adapter class behaves like a SAX2
XMLReader
object, but gets its input from the SAX1
Parser
object that is passed to the constructor.
In order to make this work, it implements the deprecated SAX1
DocumentHandler
interface so that it can receive
events from the Parser
.
ParserAdapter
provides its own layer of namespace
processing to convert a namespace-unaware Parser
into a namespace-aware XMLReader
. This class is
useful when working you are working with a legacy API that supplies a
SAX1 Parser
object, but want to work with that
parser using the SAX2 XMLReader
API: to use it,
simply pass the Parser
object to the
ParserAdapter( )
constructor and use the resulting
object as you would use any other XMLReader
object.
There is not perfect congruence between the SAX1 and SAX2 APIs, and a
Parser
cannot be perfectly adapted to a
XMLReader
. In particular, a
ParserAdapter
will never call the
skippedEntity( )
handler method because the SAX1
Parser
API does not provide notification of
skipped entities. Also, it does not attempt to determine whether two
namespace-prefixed attributes of an element actually resolve to the
same attribute.
See also XMLReaderAdapter
, an adapter that works
in the reverse direction to make a SAX2 parser behave like a SAX1
parser.
Figure 22-17. org.xml.sax.helpers.ParserAdapter
public class ParserAdapter implements org.xml.sax.DocumentHandler, ...
Get Java in a Nutshell, 5th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.