Added in API level 1

XMLReaderAdapter

public class XMLReaderAdapter
extends Object implements ContentHandler, Parser

java.lang.Object
   ↳ org.xml.sax.helpers.XMLReaderAdapter


Adapt a SAX2 XMLReader as a SAX1 Parser.

This module, both source code and documentation, is in the Public Domain, and comes with NO WARRANTY. See http://www.saxproject.org for further information.

This class wraps a SAX2 XMLReader and makes it act as a SAX1 Parser. The XMLReader must support a true value for the http://xml.org/sax/features/namespace-prefixes property or parsing will fail with a SAXException; if the XMLReader supports a false value for the http://xml.org/sax/features/namespaces property, that will also be used to improve efficiency.

See also:

Summary

Public constructors

XMLReaderAdapter()

Create a new adapter.

XMLReaderAdapter(XMLReader xmlReader)

Create a new adapter.

Public methods

void characters(char[] ch, int start, int length)

Adapt a SAX2 characters event.

void endDocument()

End document event.

void endElement(String uri, String localName, String qName)

Adapt a SAX2 end element event.

void endPrefixMapping(String prefix)

Adapt a SAX2 end prefix mapping event.

void ignorableWhitespace(char[] ch, int start, int length)

Adapt a SAX2 ignorable whitespace event.

void parse(InputSource input)

Parse the document.

void parse(String systemId)

Parse the document.

void processingInstruction(String target, String data)

Adapt a SAX2 processing instruction event.

void setDTDHandler(DTDHandler handler)

Register the DTD event handler.

void setDocumentHandler(DocumentHandler handler)

Register the SAX1 document event handler.

void setDocumentLocator(Locator locator)

Set a document locator.

void setEntityResolver(EntityResolver resolver)

Register the entity resolver.

void setErrorHandler(ErrorHandler handler)

Register the error event handler.

void setLocale(Locale locale)

Set the locale for error reporting.

void skippedEntity(String name)

Adapt a SAX2 skipped entity event.

void startDocument()

Start document event.

void startElement(String uri, String localName, String qName, Attributes atts)

Adapt a SAX2 start element event.

void startPrefixMapping(String prefix, String uri)

Adapt a SAX2 start prefix mapping event.

Inherited methods

Object clone()

Creates and returns a copy of this object.

boolean equals(Object obj)

Indicates whether some other object is "equal to" this one.

void finalize()

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

final Class<?> getClass()

Returns the runtime class of this Object.

int hashCode()

Returns a hash code value for the object.

final void notify()

Wakes up a single thread that is waiting on this object's monitor.

final void notifyAll()

Wakes up all threads that are waiting on this object's monitor.

String toString()

Returns a string representation of the object.

final void wait(long timeoutMillis, int nanos)

Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.

final void wait(long timeoutMillis)

Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.

final void wait()

Causes the current thread to wait until it is awakened, typically by being notified or interrupted.

abstract void characters(char[] ch, int start, int length)

Receive notification of character data.

abstract void endDocument()

Receive notification of the end of a document.

abstract void endElement(String uri, String localName, String qName)

Receive notification of the end of an element.

abstract void endPrefixMapping(String prefix)

End the scope of a prefix-URI mapping.

abstract void ignorableWhitespace(char[] ch, int start, int length)

Receive notification of ignorable whitespace in element content.

abstract void processingInstruction(String target, String data)

Receive notification of a processing instruction.

abstract void setDocumentLocator(Locator locator)

Receive an object for locating the origin of SAX document events.

abstract void skippedEntity(String name)

Receive notification of a skipped entity.

abstract void startDocument()

Receive notification of the beginning of a document.

abstract void startElement(String uri, String localName, String qName, Attributes atts)

Receive notification of the beginning of an element.

abstract void startPrefixMapping(String prefix, String uri)

Begin the scope of a prefix-URI Namespace mapping.

abstract void parse(InputSource source)

Parse an XML document.

abstract void parse(String systemId)

Parse an XML document from a system identifier (URI).

abstract void setDTDHandler(DTDHandler handler)

Allow an application to register a DTD event handler.

abstract void setDocumentHandler(DocumentHandler handler)

Allow an application to register a document event handler.

abstract void setEntityResolver(EntityResolver resolver)

Allow an application to register a custom entity resolver.

abstract void setErrorHandler(ErrorHandler handler)

Allow an application to register an error event handler.

abstract void setLocale(Locale locale)

Allow an application to request a locale for errors and warnings.

Public constructors

XMLReaderAdapter

Added in API level 1
public XMLReaderAdapter ()

Create a new adapter.

Use the "org.xml.sax.driver" property to locate the SAX2 driver to embed.

Throws
SAXException If the embedded driver cannot be instantiated or if the org.xml.sax.driver property is not specified.

XMLReaderAdapter

Added in API level 1
public XMLReaderAdapter (XMLReader xmlReader)

Create a new adapter.

Create a new adapter, wrapped around a SAX2 XMLReader. The adapter will make the XMLReader act like a SAX1 Parser.

Parameters
xmlReader XMLReader: The SAX2 XMLReader to wrap.

Throws
NullPointerException If the argument is null.

Public methods

characters

Added in API level 1
public void characters (char[] ch, 
                int start, 
                int length)

Adapt a SAX2 characters event.

Parameters
ch char: An array of characters.

start int: The starting position in the array.

length int: The number of characters to use.

Throws
SAXException The client may raise a processing exception.

endDocument

Added in API level 1
public void endDocument ()

End document event.

Throws
SAXException The client may raise a processing exception.

endElement

Added in API level 1
public void endElement (String uri, 
                String localName, 
                String qName)

Adapt a SAX2 end element event.

Parameters
uri String: The Namespace URI.

localName String: The Namespace local name.

qName String: The qualified (prefixed) name.

Throws
SAXException The client may raise a processing exception.

endPrefixMapping

Added in API level 1
public void endPrefixMapping (String prefix)

Adapt a SAX2 end prefix mapping event.

Parameters
prefix String: The prefix being mapped.

ignorableWhitespace

Added in API level 1
public void ignorableWhitespace (char[] ch, 
                int start, 
                int length)

Adapt a SAX2 ignorable whitespace event.

Parameters
ch char: An array of characters.

start int: The starting position in the array.

length int: The number of characters to use.

Throws
SAXException The client may raise a processing exception.

parse

Added in API level 1
public void parse (InputSource input)

Parse the document.

This method will throw an exception if the embedded XMLReader does not support the http://xml.org/sax/features/namespace-prefixes property.

Parameters
input InputSource: An input source for the document.

Throws
IOException If there is a problem reading the raw content of the document.
SAXException If there is a problem processing the document.

parse

Added in API level 1
public void parse (String systemId)

Parse the document.

This method will throw an exception if the embedded XMLReader does not support the http://xml.org/sax/features/namespace-prefixes property.

Parameters
systemId String: The absolute URL of the document.

Throws
IOException If there is a problem reading the raw content of the document.
SAXException If there is a problem processing the document.

processingInstruction

Added in API level 1
public void processingInstruction (String target, 
                String data)

Adapt a SAX2 processing instruction event.

Parameters
target String: The processing instruction target.

data String: The remainder of the processing instruction

Throws
SAXException The client may raise a processing exception.

setDTDHandler

Added in API level 1
public void setDTDHandler (DTDHandler handler)

Register the DTD event handler.

Parameters
handler DTDHandler: The new DTD event handler.

setDocumentHandler

Added in API level 1
public void setDocumentHandler (DocumentHandler handler)

Register the SAX1 document event handler.

Note that the SAX1 document handler has no Namespace support.

Parameters
handler DocumentHandler: The new SAX1 document event handler.

setDocumentLocator

Added in API level 1
public void setDocumentLocator (Locator locator)

Set a document locator.

Parameters
locator Locator: The document locator.

setEntityResolver

Added in API level 1
public void setEntityResolver (EntityResolver resolver)

Register the entity resolver.

Parameters
resolver EntityResolver: The new resolver.

setErrorHandler

Added in API level 1
public void setErrorHandler (ErrorHandler handler)

Register the error event handler.

Parameters
handler ErrorHandler: The new error event handler.

setLocale

Added in API level 1
public void setLocale (Locale locale)

Set the locale for error reporting.

This is not supported in SAX2, and will always throw an exception.

Parameters
locale Locale: the locale for error reporting.

Throws
SAXException Thrown unless overridden.

skippedEntity

Added in API level 1
public void skippedEntity (String name)

Adapt a SAX2 skipped entity event.

Parameters
name String: The name of the skipped entity.

Throws
SAXException Throwable by subclasses.

startDocument

Added in API level 1
public void startDocument ()

Start document event.

Throws
SAXException The client may raise a processing exception.

startElement

Added in API level 1
public void startElement (String uri, 
                String localName, 
                String qName, 
                Attributes atts)

Adapt a SAX2 start element event.

Parameters
uri String: The Namespace URI.

localName String: The Namespace local name.

qName String: The qualified (prefixed) name.

atts Attributes: The SAX2 attributes.

Throws
SAXException The client may raise a processing exception.

startPrefixMapping

Added in API level 1
public void startPrefixMapping (String prefix, 
                String uri)

Adapt a SAX2 start prefix mapping event.

Parameters
prefix String: The prefix being mapped.

uri String: The Namespace URI being mapped to.