Class XMLReaderAdapter
- All Implemented Interfaces:
-
ContentHandler,Parser
public class XMLReaderAdapter extends Object implements Parser, ContentHandler
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.
Constructor Summary
| Constructor | Description |
|---|---|
XMLReaderAdapter() |
Create a new adapter. |
XMLReaderAdapter |
Create a new adapter. |
Method Summary
| Modifier and Type | Method | Description |
|---|---|---|
void |
characters |
Adapt a SAX2 characters event. |
void |
endDocument() |
End document event. |
void |
endElement |
Adapt a SAX2 end element event. |
void |
endPrefixMapping |
Adapt a SAX2 end prefix mapping event. |
void |
ignorableWhitespace |
Adapt a SAX2 ignorable whitespace event. |
void |
parse |
Parse the document. |
void |
parse |
Parse the document. |
void |
processingInstruction |
Adapt a SAX2 processing instruction event. |
void |
setDocumentHandler |
Register the SAX1 document event handler. |
void |
setDocumentLocator |
Set a document locator. |
void |
setDTDHandler |
Register the DTD event handler. |
void |
setEntityResolver |
Register the entity resolver. |
void |
setErrorHandler |
Register the error event handler. |
void |
setLocale |
Set the locale for error reporting. |
void |
skippedEntity |
Adapt a SAX2 skipped entity event. |
void |
startDocument() |
Start document event. |
void |
startElement |
Adapt a SAX2 start element event. |
void |
startPrefixMapping |
Adapt a SAX2 start prefix mapping event. |
Methods declared in class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods declared in interface org.xml.sax.ContentHandler
declaration
Constructor Details
XMLReaderAdapter
public XMLReaderAdapter() throws SAXException
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
public XMLReaderAdapter(XMLReader xmlReader)
Create a new adapter, wrapped around a SAX2 XMLReader. The adapter will make the XMLReader act like a SAX1 Parser.
- Parameters:
-
xmlReader- The SAX2 XMLReader to wrap. - Throws:
-
NullPointerException- If the argument is null.
Method Details
setLocale
public void setLocale(Locale locale) throws SAXException
This is not supported in SAX2, and will always throw an exception.
- Specified by:
-
setLocalein interfaceParser - Parameters:
-
locale- the locale for error reporting. - Throws:
-
SAXException- Thrown unless overridden. - See Also:
setEntityResolver
public void setEntityResolver(EntityResolver resolver)
- Specified by:
-
setEntityResolverin interfaceParser - Parameters:
-
resolver- The new resolver. - See Also:
setDTDHandler
public void setDTDHandler(DTDHandler handler)
- Specified by:
-
setDTDHandlerin interfaceParser - Parameters:
-
handler- The new DTD event handler. - See Also:
setDocumentHandler
public void setDocumentHandler(DocumentHandler handler)
Note that the SAX1 document handler has no Namespace support.
- Specified by:
-
setDocumentHandlerin interfaceParser - Parameters:
-
handler- The new SAX1 document event handler. - See Also:
setErrorHandler
public void setErrorHandler(ErrorHandler handler)
- Specified by:
-
setErrorHandlerin interfaceParser - Parameters:
-
handler- The new error event handler. - See Also:
parse
public void parse(String systemId) throws IOException, SAXException
This method will throw an exception if the embedded XMLReader does not support the http://xml.org/sax/features/namespace-prefixes property.
- Specified by:
-
parsein interfaceParser - Parameters:
-
systemId- 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. - See Also:
parse
public void parse(InputSource input) throws IOException, SAXException
This method will throw an exception if the embedded XMLReader does not support the http://xml.org/sax/features/namespace-prefixes property.
- Specified by:
-
parsein interfaceParser - Parameters:
-
input- 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. - See Also:
setDocumentLocator
public void setDocumentLocator(Locator locator)
- Specified by:
-
setDocumentLocatorin interfaceContentHandler - Parameters:
-
locator- The document locator. - See Also:
startDocument
public void startDocument() throws SAXException
- Specified by:
-
startDocumentin interfaceContentHandler - Throws:
-
SAXException- The client may raise a processing exception. - See Also:
endDocument
public void endDocument() throws SAXException
- Specified by:
-
endDocumentin interfaceContentHandler - Throws:
-
SAXException- The client may raise a processing exception. - See Also:
startPrefixMapping
public void startPrefixMapping(String prefix, String uri)
- Specified by:
-
startPrefixMappingin interfaceContentHandler - Parameters:
-
prefix- The prefix being mapped. -
uri- The Namespace URI being mapped to. - See Also:
endPrefixMapping
public void endPrefixMapping(String prefix)
- Specified by:
-
endPrefixMappingin interfaceContentHandler - Parameters:
-
prefix- The prefix being mapped. - See Also:
startElement
public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException
- Specified by:
-
startElementin interfaceContentHandler - Parameters:
-
uri- The Namespace URI. -
localName- The Namespace local name. -
qName- The qualified (prefixed) name. -
atts- The SAX2 attributes. - Throws:
-
SAXException- The client may raise a processing exception. - See Also:
endElement
public void endElement(String uri, String localName, String qName) throws SAXException
- Specified by:
-
endElementin interfaceContentHandler - Parameters:
-
uri- The Namespace URI. -
localName- The Namespace local name. -
qName- The qualified (prefixed) name. - Throws:
-
SAXException- The client may raise a processing exception. - See Also:
characters
public void characters(char[] ch, int start, int length) throws SAXException
- Specified by:
-
charactersin interfaceContentHandler - Parameters:
-
ch- An array of characters. -
start- The starting position in the array. -
length- The number of characters to use. - Throws:
-
SAXException- The client may raise a processing exception. - See Also:
ignorableWhitespace
public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException
- Specified by:
-
ignorableWhitespacein interfaceContentHandler - Parameters:
-
ch- An array of characters. -
start- The starting position in the array. -
length- The number of characters to use. - Throws:
-
SAXException- The client may raise a processing exception. - See Also:
processingInstruction
public void processingInstruction(String target, String data) throws SAXException
- Specified by:
-
processingInstructionin interfaceContentHandler - Parameters:
-
target- The processing instruction target. -
data- The remainder of the processing instruction - Throws:
-
SAXException- The client may raise a processing exception. - See Also:
skippedEntity
public void skippedEntity(String name) throws SAXException
- Specified by:
-
skippedEntityin interfaceContentHandler - Parameters:
-
name- The name of the skipped entity. - Throws:
-
SAXException- Throwable by subclasses. - See Also:
© 1993, 2021, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
https://docs.oracle.com/en/java/javase/17/docs/api/java.xml/org/xml/sax/helpers/XMLReaderAdapter.html