Mod??SAX: Feature Matrix

David Megginson david at megginson.com
Fri Mar 12 14:45:24 GMT 1999


It would be interesting to put together a feature matrix representing
current practice among SAX parsers/drivers, at least in the Java
world.  Assuming that I simply wrapped the existing drivers with a
Mod??Parser adapter, what features would and would not be supported?

>From my fuzzy recollection, here's what AElfred supported just about a 
year ago before I gave it up:

                                 true              false
------------------------------------------------------------------------
validation                       no                yes
external-general-entities        yes               no
external-parameter-entities      yes               no
namespaces                       no                yes
normalize-text                   yes               no
use-locator                      yes               no

(Wherever there's a 'no' answer, the driver should throw a
SAXNotSupportedException).  Actually, it would probably be safe to
accept false for 'normalize-text' as well.  If I were to wrap the
AElfred driver, then, I'd do something like this (there's likely some
kind of a static initialisation trap here, but it should be good
enough as an unreliable example):


public class AElfredModParser extends com.microstar.xml.SAXDriver
                              implements org.xml.sax.ModParser
{
  private static Hashtable featureTable = new Hashtable();
  private static final Object TRUE = new Object();
  private static final Object FALSE = new Object();
  private static final Object TRUEFALSE = new Object();
  private static final String FEATURE_NS = "http://xml.org/sax/features/";

  static {
    featureTable.put(FEATURE_NS + "validation", FALSE);
    featureTable.put(FEATURE_NS + "external-general-entities", TRUE);
    featureTable.put(FEATURE_NS + "external-parameter-entities", TRUE);
    featureTable.put(FEATURE_NS + "namespaces", TRUE);
    featureTable.put(FEATURE_NS + "normalize-text", TRUEFALSE);
    featureTable.put(FEATURE_NS + "use-locator", TRUE);
  }

  public void setFeature (String featureID, boolean state)
    throws SAXNotSupportedException
  {
    Object allowedState = featureTable.get(featureID);
    if (allowedState == null) {
      throw new SAXNotRecognizedException();
    } else if ((state && allowedState == FALSE) ||
               (!state && allowedState == TRUE)) {
      throw new SAXNotSupportedException();
    }
  }

  // etc. for setHandler, set, and get
}


All the best,


David

-- 
David Megginson                 david at megginson.com
           http://www.megginson.com/

xml-dev: A list for W3C XML Developers. To post, mailto:xml-dev at ic.ac.uk
Archived as: http://www.lists.ic.ac.uk/hypermail/xml-dev/ and on CD-ROM/ISBN 981-02-3594-1
To (un)subscribe, mailto:majordomo at ic.ac.uk the following message;
(un)subscribe xml-dev
To subscribe to the digests, mailto:majordomo at ic.ac.uk the following message;
subscribe xml-dev-digest
List coordinator, Henry Rzepa (mailto:rzepa at ic.ac.uk)




More information about the Xml-dev mailing list