All Packages  Class Hierarchy  This Package  Previous  Next  Index

Interface org.xml.sax.DocumentHandler

public interface DocumentHandler
A callback interface for basic XML document events.

This interface is part of the Java implementation of SAX, the Simple API for XML. It is free for both commercial and non-commercial use, and is distributed with no warrantee, real or implied.

This is the main handler for basic document events; it provides information on roughly the same level as the ESIS in full SGML, concentrating on logical structure rather than lexical representation.

If you do not set a document handler, then by default all of these events will simply be ignored.

Author:
David Megginson, Microstar Software Ltd.
See Also:
Parser@setDocumentHandler

Method Index

 o characters(char[], int, int)
Handle significant character data.
 o doctype(String, String, String)
Handle the document type declaration.
 o endDocument()
Handle the end of a document.
 o endElement(String)
Handle the end of an element.
 o ignorable(char[], int, int)
Handle ignorable whitespace.
 o processingInstruction(String, String)
Handle a processing instruction.
 o startDocument()
Handle the start of a document.
 o startElement(String, AttributeMap)
Handle the start of an element.

Methods

 o startDocument
 public abstract void startDocument() throws Exception
Handle the start of a document.

This is the first event called by a SAX-conformant parser, so you can use it to allocate and initialise new objects for the document.

Throws: Exception
You may throw any exception.
 o endDocument
 public abstract void endDocument() throws Exception
Handle the end of a document.

This is the last event called by a SAX-conformant parser, so you can use it to finalize and clean up objects for the document.

Throws: Exception
You may throw any exception.
 o doctype
 public abstract void doctype(String name,
                              String publicID,
                              String systemID) throws Exception
Handle the document type declaration.

This will appear only if the XML document contains a DOCTYPE declaration.

Parameters:
name - The document type name.
publicID - The public identifier of the external DTD subset (if any), or null.
systemID - The system identifier of the external DTD subset (if any), or null.
name - The document type name.
Throws: Exception
You may throw any exception.
 o startElement
 public abstract void startElement(String name,
                                   AttributeMap attributes) throws Exception
Handle the start of an element.

Please note that the information in the attributes parameter will be accurate only for the duration of this handler: if you need to use the information elsewhere, you should copy it.

Parameters:
name - The element type name.
attributes - The available attributes.
Throws: Exception
You may throw any exception.
 o endElement
 public abstract void endElement(String name) throws Exception
Handle the end of an element.

Throws: Exception
You may throw any exception.
 o characters
 public abstract void characters(char ch[],
                                 int start,
                                 int length) throws Exception
Handle significant character data.

Please note that the contents of the array will be accurate only for the duration of this handler: if you need to use them elsewhere, you should make your own copy, possible by constructing a string:

 String data = new String(ch, start, length);
 

Parameters:
ch - An array of characters.
start - The starting position in the array.
length - The number of characters to use in the array.
Throws: Exception
You may throw any exception.
 o ignorable
 public abstract void ignorable(char ch[],
                                int start,
                                int length) throws Exception
Handle ignorable whitespace.

Please note that the contents of the array will be accurate only for the duration of this handler: if you need to use them elsewhere, you should make your own copy, possible by constructing a string:

 String whitespace = new String(ch, start, length);
 

Parameters:
ch - An array of whitespace characters.
start - The starting position in the array.
length - The number of characters to use in the array.
Throws: Exception
You may throw any exception.
 o processingInstruction
 public abstract void processingInstruction(String name,
                                            String remainder) throws Exception
Handle a processing instruction.

XML processing instructions have two parts: a target, which is a name, followed optionally by data.

Throws: Exception
You may throw any exception.

All Packages  Class Hierarchy  This Package  Previous  Next  Index