org.brownell.xml
Class DomParser2

java.lang.Object
  |
  +--org.brownell.xml.DomParser2

public class DomParser2
extends java.lang.Object
implements org.xml.sax.Configurable, org.xml.sax.Parser

This parser emits SAX2 parsing events as it traverses a DOM tree, using any conformant implementation of DOM. It exposes all SAX 1.0 features, and the following SAX 2 (1-June-1999 draft) features and properties (as identified by standard URIs which are not fully provided here).

Name Type Notes
validation Feature false (does no parsing)
external-general-entities Feature false (does no parsing)
external-parameter-entities Feature false (does no parsing)
namespaces Feature Value is fixed at false
normalize-text Feature Value is fixed at false; if you want normalized events for characters, you can get them by first normalizing the DOM tree.
use-locator Feature false (does no parsing)
 
dom-node Property This property may be set before parsing to hold a DOM Document node; any arguments given to parse methods are ignored. When retrieved during a parse, this value contains the "current" DOM node.
DeclHandler Property A declaration handler may be provided. Declaration of external general entities is exposed, but not parameter entities; none of the entity names reported here will begin with "%".
LexicalHandler Property A lexical handler may be provided. While the start and end of any external subset are reported, expansion of other parameter entities (e.g. inside attribute list declarations) is not exposed. Expansion of general entities within attributes is also not exposed (see below).

Note that the current SAX2 draft has no standard way to provide the initial DOM document. This parser supports that facility through the property holding the current DOM node: it may be set when not parsing, to a DOM Document node which is used to generate the events of the next parse.

The consequences of modifying a DOM document tree as it is being walked by this "parser" are unspecified; don't do it!

Version:
1.0 (23 June 1999)
Author:
David Brownell (db@post.harvard.edu)

Constructor Summary
DomParser2()
          Constructs an unitialized SAX2 parser.
 
Method Summary
 boolean getFeature(java.lang.String featureId)
          SAX2: Tells whether this parser supports the specified feature.
 java.lang.Object getProperty(java.lang.String propertyId)
          SAX2: Returns the specified property.
 void parse(org.xml.sax.InputSource input)
          SAX1: Parses the previously provided DOM document (the input parameter is ignored).
 void parse(java.lang.String uri)
          SAX1: Parses the previously provided DOM document (the input parameter is ignored).
 void setDocumentHandler(org.xml.sax.DocumentHandler handler)
          SAX1: Provides an object which receives callbacks for the most significant document information.
 void setDTDHandler(org.xml.sax.DTDHandler handler)
          SAX1: Provides an object which may be used to intercept declarations related to notations and unparsed entities.
 void setEntityResolver(org.xml.sax.EntityResolver resolver)
          SAX1: Provides an object which may be used when resolving external entities during parsing (both general and parameter entities).
 void setErrorHandler(org.xml.sax.ErrorHandler handler)
          SAX1: Provides an object which receives callbacks for XML errors of all levels (fatal, nonfatal, warning).
 void setFeature(java.lang.String featureId, boolean state)
          SAX2: Sets the state of features supported in this parser.
 void setLocale(java.util.Locale locale)
          SAX1: Identifies the locale which the parser should use for the diagnostics it provides.
 void setProperty(java.lang.String propertyId, java.lang.Object property)
          SAX2: Assigns the specified property.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DomParser2

public DomParser2()
Constructs an unitialized SAX2 parser.
Method Detail

setErrorHandler

public void setErrorHandler(org.xml.sax.ErrorHandler handler)
SAX1: Provides an object which receives callbacks for XML errors of all levels (fatal, nonfatal, warning).
Specified by:
setErrorHandler in interface org.xml.sax.Parser

setDocumentHandler

public void setDocumentHandler(org.xml.sax.DocumentHandler handler)
SAX1: Provides an object which receives callbacks for the most significant document information.
Specified by:
setDocumentHandler in interface org.xml.sax.Parser

setDTDHandler

public void setDTDHandler(org.xml.sax.DTDHandler handler)
SAX1: Provides an object which may be used to intercept declarations related to notations and unparsed entities.
Specified by:
setDTDHandler in interface org.xml.sax.Parser

setEntityResolver

public void setEntityResolver(org.xml.sax.EntityResolver resolver)
SAX1: Provides an object which may be used when resolving external entities during parsing (both general and parameter entities).
Specified by:
setEntityResolver in interface org.xml.sax.Parser

setLocale

public void setLocale(java.util.Locale locale)
               throws org.xml.sax.SAXException
SAX1: Identifies the locale which the parser should use for the diagnostics it provides.
Specified by:
setLocale in interface org.xml.sax.Parser
Throws:
org.xml.sax.SAXException - as defined in the specification for org.xml.sax.Parser.setLocale()

parse

public void parse(java.lang.String uri)
           throws org.xml.sax.SAXException,
                  java.io.IOException
SAX1: Parses the previously provided DOM document (the input parameter is ignored).
Specified by:
parse in interface org.xml.sax.Parser
Parameters:
uri - ignored (pass an empty string)
Throws:
org.xml.sax.SAXException - as defined in the specification for org.xml.sax.Parser.parse()
java.io.IOException - as defined in the specification for org.xml.sax.Parser.parse()

parse

public void parse(org.xml.sax.InputSource input)
           throws org.xml.sax.SAXException,
                  java.io.IOException
SAX1: Parses the previously provided DOM document (the input parameter is ignored).
Specified by:
parse in interface org.xml.sax.Parser
Parameters:
input - ignored
Throws:
org.xml.sax.SAXException - as defined in the specification for org.xml.sax.Parser.parse()
java.io.IOException - as defined in the specification for org.xml.sax.Parser.parse()

getFeature

public boolean getFeature(java.lang.String featureId)
                   throws org.xml.sax.SAXException
SAX2: Tells whether this parser supports the specified feature. At this time, this directly parallels the underlying parser, except that the use of validation can be enabled or disabled (since Sun's package has two separate SAX 1.0 parsers).
Specified by:
getFeature in interface org.xml.sax.Configurable
Throws:
org.xml.sax.SAXException - as defined in the specification for org.xml.sax.Configurable.getFeature()

getProperty

public java.lang.Object getProperty(java.lang.String propertyId)
                             throws org.xml.sax.SAXException
SAX2: Returns the specified property. At this time only the declaration and lexical handlers, and current the "DOM" object, are supported.
Specified by:
getProperty in interface org.xml.sax.Configurable
Throws:
org.xml.sax.SAXException - as defined in the specification for org.xml.sax.Configurable.getProperty()

setFeature

public void setFeature(java.lang.String featureId,
                       boolean state)
                throws org.xml.sax.SAXException
SAX2: Sets the state of features supported in this parser. At this writing, no feature's state is mutable.
Specified by:
setFeature in interface org.xml.sax.Configurable
Throws:
org.xml.sax.SAXException - as defined in the specification for org.xml.sax.Configurable.setFeature()

setProperty

public void setProperty(java.lang.String propertyId,
                        java.lang.Object property)
                 throws org.xml.sax.SAXException
SAX2: Assigns the specified property. At this time only declaration and lexical handlers, and the initial DOM document, are supported. These must not be changed to values of the wrong type. Like SAX1 handlers, these handlers may be changed at any time. Like SAX1 input source or document URI, the initial DOM document may not be changed during a parse.
Specified by:
setProperty in interface org.xml.sax.Configurable
Throws:
org.xml.sax.SAXException - as defined in the specification for org.xml.sax.Configurable.setProperty()