Appendix A. API ReferenceContents:This appendix is an API reference for the four lower-level Java and XML APIs covered in this book, SAX, DOM, JDOM, and JAXP. It is broken down into sections based on the API being documented. A.1. SAX 2.0SAX 2.0 provides a sequential look into an XML document. Detailed in Chapter 3, "SAX" and Chapter 4, "Advanced SAX ", SAX defines a set of interfaces that can be implemented and will be invoked as callbacks during the XML parsing process. The SAX packages are detailed here, with the classes and interfaces listed alphabetically. In the org.xml.sax.helpers package, most of the methods in the helper classes are implementations of interfaces already defined in the core SAX package (org.xml.sax). A.1.1. Package: org.xml.saxThis package contains the core interfaces and classes for SAX 2.0. Most of the interfaces defined are intended to be implemented by you, the Java developer, with the exception of the actual XMLReader and Attributes implementation. These interfaces should be implemented by your vendor's XML parsing software. In addition, several exceptions that SAX methods are allowed to throw are defined. Several of the interfaces defined here are part of the SAX 1.0 and 2.0 alpha distributions, and are now deprecated. A.1.1.1. AttributeList [deprecated]This interface was defined in SAX 1.0, and is now deprecated. The Attributes interface should be used instead of AttributeList for SAX 2.0 implementations.
A.1.1.2. AttributesThis interface represents a listing of XML attributes. It is reported to the callbacks associated with the start of element (startElement( ) in ContentHandler), and is somewhat analogous to a Java Vector. The number of attributes represented can be obtained, as well as various views of the attributes' names (local, namespace prefix and URI, and raw) and values. Additionally, methods are available for locating the index of an attribute given its name. The primary difference between this interface and its predecessor, AttributeList, is that this interface is namespace-aware.
A.1.1.3. ContentHandlerThis interface defines the callback methods available to an application that deal with the content of the XML document being parsed. These include notification of the start and end of parsing (which precede and follow all other handler callbacks, respectively), processing instructions, and entities that may be skipped by nonvalidating parsers. Element callbacks, complete with namespace mappings, are also made available.
A.1.1.4. DocumentHandlerThis interface was defined in SAX 1.0, and is now deprecated. The ContentHandler interface should be used instead of DocumentHandler for SAX 2.0 implementations.
A.1.1.5. DTDHandlerThis interface defines callbacks that are invoked in the process of parsing a DTD. Note that this interface does not provide information about the constraints within the DTD, but instead about references to unparsed entities and NOTATION declarations, indicating items that are generally unparsed data.
A.1.1.6. EntityResolverThis interface allows applications to intervene in the process of referencing external entities, such as an XML document that references a DTD or stylesheet. By implementing this interface, a modified or even completely different SAX InputSource can be returned to the calling program. Additionally, null can be returned to indicate that a normal URI connection should be opened to the specified system ID.
A.1.1.7. ErrorHandlerThis interface allows custom behavior to be attached to the three types of problem conditions that can occur within the lifecycle of XML parsing. Each receives the SAXParseException indicating what problem initiated the callback. The SAXException is provided to allow a means of throwing an exception that could stop parsing altogether.
A.1.1.8. HandlerBaseThis helper class provides empty implementations of all the SAX 1.0 core handler interfaces, and can be extended to allow the quick addition of handlers by overriding methods with application-defined behavior. This class was defined in SAX 1.0, and is now deprecated. The org.xml.sax.helpers.DefaultHandler class should be used instead of HandlerBase for SAX 2.0 implementations.
A.1.1.9. InputSourceThis class encapsulates all information about a resource used in XML processing. This can be as little as a String or InputStream used for locating input, or as complex as an entity with a public ID and system ID as well as a URI reference (such as a DTD publicly defined). This class is the preferred wrapper for passing input into a SAX parser.
A.1.1.10. LocatorThis class is a complement to an XML document or other parsed construct, as it provides the document's system ID and public ID as well as information about the location within the file being processed. This is particularly helpful for use in IDE applications and for identifying where errors occur in parsing.
A.1.1.11. ParserThis interface was defined in SAX 1.0, and is now deprecated. The XMLReader interface should be used instead for SAX 2.0 implementations.
A.1.1.12. SAXExceptionThis is the core exception thrown by SAX callbacks and parser implementations. Because it is often thrown as a result of other exceptions, it has a constructor that allows the passing in of a lower-level Exception as well as an accessor method to retrieve the originating Exception. It is also the base class for all other SAX Exception classes.
A.1.1.13. SAXNotRecognizedExceptionThis class provides a means for an XMLReader implementation to throw an error when an unrecognized identifier is received. This is most common in the setProperty( ) and setFeature( ) methods (as well as their accessor counterparts) when a URI is supplied about which the parser has no information.
A.1.1.14. SAXNotSupportedExceptionThis class provides a means for an XMLReader implementation to throw an error when an unsupported (but recognized) identifier is received. This is most common in the setProperty( ) and setFeature( ) methods (as well as their accessor counterparts) when a URI is supplied for which the parser has no supporting code.
A.1.1.15. SAXParseExceptionThis class represents exceptions that can occur during the parsing process. Information about the location of the error within the XML document is available through this class's accessor methods. The preferred means of supplying this information to the class is through a Locator, but the line and column number where problems occurred can be supplied directly through overloaded constructors. The system ID and public ID of the document with the problem are also made available to the class through various means in the constructors.
A.1.1.16. XMLFilterThis class is analogous to an XMLReader, but it obtains its events from another XMLReader rather than a static document or network resource. These filters can also be chained on each other. Their primary use is in modifying the output from a lower-level XMLReader in the chain, providing filtering of the data reported to callback methods before the final application receives notification of the data.
A.1.1.17. XMLReaderThis is the core interface that defines parsing behavior in SAX 2.0. Each vendor's XML parsing software package must include at least one implementation of this interface. It replaces the SAX 1.0 Parser interface by adding support for namespaces in a document's elements and attributes. In addition to providing an entry into parsing (with either a system ID or InputSource as input), it allows registering of the various handler interfaces that SAX 2.0 provides. The features and properties available to a SAX parser implementation are also set through this interface. A complete list of SAX core features and properties is contained in Appendix B, "SAX 2.0 Features and Properties".
A.1.2. Package: org.xml.sax.extThis package provides extensions to the SAX core classes and interfaces. Specifically, additional handlers are defined for less common processing within the SAX parsing process. XMLReader implementations are not required to support these extension handlers. A.1.2.1. DeclHandlerThis interface defines callbacks that give specific information about DTD declarations. Element and attribute definitions invoke the appropriate callback with their names (and the element names for attributes) as well as constraint information. While this is a fairly rigid set of data for attributes, elements only receive a String with the constrained model as pure text. Additionally, internal and external entity reference notifications are defined.
A.1.2.2. LexicalHandlerThis interface defines callbacks for various events that are at a document level in terms of processing, but do not affect the resulting data within the XML document. For example, the handling of a DTD declaration, comments, and entity references would invoke callbacks in implementations of this interface. Additionally, a callback is defined to signal when a CDATA section is started and ended (although the reported data will always remain the same).
A.1.3. Package: org.xml.sax.helpersThis package provides extensions to the SAX core classes and interfaces. Specifically, additional handlers are defined for less common processing within the SAX parsing process. XMLReader implementations are not required to support these extension handlers. NOTE: In the classes in this package that are default implementations of core org.xml.sax interfaces, I have left out the repeated methods for brevity. Instead, I've simply added a comment indicating what interface's methods are implemented. A.1.3.1. AttributeListImplThis class provides a default implementation of the org.xml.sax.AttributeList interface, and is deprecated in SAX 2.0. It allows addition and removal of attributes as well as a clearing of the list.
A.1.3.2. AttributesImplThis class provides a default implementation of the org.xml.sax.Attributes interface. It allows addition and removal of attributes as well as a clearing of the list.
A.1.3.3. DefaultHandlerThis helper class provides empty implementations of all the SAX 2.0 core handler interfaces, and can be extended to allow for quick addition of handlers by only overriding methods with application-defined behavior. This replaces the SAX 1.0 org.xml.sax.HandlerBase class.
A.1.3.4. LocatorImplThis class provides a default implementation of the org.xml.sax.Locator interface. It also provides a means of directly setting the line and column numbers.
A.1.3.5. NamespaceSupportThis encapsulates namespace behavior, allowing applications to not have to implement the behavior on their own (unless desired for performance reasons). It allows handling of namespace contexts in a stack fashion, and also provides the ability to process XML 1.0 names, retrieving their "namespace-aware" counterparts.
A.1.3.6. ParserAdapterThis helper class wraps a SAX 1.0 Parser implementation and makes it behave like a 2.0 XMLReader implementation (making namespace support available). The only callback that does not behave normally is skippedEntity( ) in the ContentHandler interface; it is never invoked.
A.1.3.7. ParserFactoryThis class contains methods that dynamically create an instance of a Parser implementation from a specified class name, or if none is supplied, from a system property named "org.xml.sax.driver".
A.1.3.8. XMLFilterImplThis class provides a default implementation of the org.xml.sax.XMLFilter interface.
A.1.3.9. XMLReaderAdapterThis helper class wraps a SAX 2.0 XMLReader implementation and makes it behave like a 1.0 Parser implementation (making namespace support unavailable). The namespaces feature (http://xml.org/sax/features/namespaces) must be supported, or errors in parsing will occur.
A.1.3.10. XMLReaderFactoryThis class contains methods that dynamically create an instance of an XMLReader implementation from a specified class name, or if none is supplied, from a system property named "org.xml.sax.driver".
Copyright © 2002 O'Reilly & Associates. All rights reserved. |
|
|