[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

SAX2/Java: Towards a final form

  • From: David Megginson <david@m...>
  • To: XMLDev list <xml-dev-digest@i...>
  • Date: Mon, 10 Jan 2000 10:10:19 -0500 (EST)

sax2 java
I spent some time over the holidays working on a new SAX2 package, and
it didn't take me long to decide that redoing everything in a new
org.xml.sax2 package and creating all of the adapters was going to be
too much of a hill for me to climb right now.

We really, really, *really* need SAX2 -- a lot of the debate about
Namespaces, for example, wouldn't exist if there were a simple API for
getting at Namespace information.  Here's a new suggestion that both
preserves a lot of SAX1 and provides a clean path for future SAX
development without some of the SAX1 baggage:

1. Deprecate Parser, DocumentHandler, and AttributeList.

2. Create a new class, ContentHandler, that duplicates the current
   DocumentHandler but adds proper support for Namespace processing
   and for reporting skipped entities (an XML 1.0 requirement that
   SAX1 never met, as John Cowan never got tired of reminding me).

3. Create a new interface, Attributes, that replaces AttributeList.

4. Create a new class, XMLReader, that (for now) extends Parser and
   adds support for the configurability and for setting the
   ContentHandler -- add a warning that this class will likely not
   extend Parser in future versions of SAX.

5. Add the SAXNotRecognizedException and SAXNotSupportedException
   classes.

6. Add the LexicalHandler and DeclarationHandler classes as previously
   planned, but put them in a different extensions package and don't
   provide explicit setters for XMLReader (since we'll be adding more
   extension handlers later, and all extension handlers should be set
   with setProperty).

7. Write the (now fairly simple) adapters for SAX1 parsers.

8. Rewrite some of the existing concrete classes to improve efficiency 
   or fix bugs.

9. Rewrite HandlerBase.


Here are the three new core interfaces:


====================8<====================8<====================

  public interface XMLReader extends Parser
  {
    //
    // Parser.setLocale and Parser.setDocumentHandler are
    // deprecated.
    //

    //
    // Configure the reader.
    //
    public void setFeature (String name, boolean state)
      throws SAXNotRecognizedException, SAXNotSupportedException;
    public boolean getFeature (String name)
      throws SAXNotRecognizedException;
    public void setProperty (String name, Object value)
      throws SAXNotRecognizedException, SAXNotSupportedException;
    public Object getProperty (String name)   
      throws SAXNotRecognizedException;

    //
    // Register handlers.
    //
    public void setEntityResolver (EntityResolver resolver);
    public EntityResolver getEntityResolver ();
    public void setDTDHandler (DTDHandler handler);
    public DTDHandler getDTDHandler ();
    public void setContentHandler (ContentHandler handler);
    public ContentHandler getContentHandler ();
    public void setErrorHandler (ErrorHandler handler);
    public ErrorHandler getErrorHandler ();

    //
    // Run a parse.
    //
    public void parse (String systemId)
      throws IOException, SAXException;
    public void parse (InputSource input)
      throws IOException, SAXException;
  }

====================8<====================8<====================

  public interface Attributes
  {
    public int getLength ();

    public String getURI (int pos);
    public String getLocalName (int pos);
    public String getRawName (int pos);
    public String getType (int pos);
    public String getValue (int pos);

    public String getType (String uri, String localName);
    public String getType (String rawName);
    public String getValue (String uri, String localName);
    public String getValue (String rawName);
  }

====================8<====================8<====================

  public interface ContentHandler
  {
    public void setDocumentLocator (Locator locator);

    public void startDocument ()
      throws SAXException;
    public void endDocument ()
      throws SAXException;

    public void startPrefixMapping (String prefix, String uri)
      throws SAXException;
    public void endPrefixMapping (String prefix)
      throws SAXException;

    public void startElement (String uri, String localName,
                              String rawName, Attributes atts)
      throws SAXException;
    public void endElement (String uri, String localName, String rawName)
      throws SAXException;

    public void characters (char ch[], int start, int length)
      throws SAXException;

    public void ignorableWhitespace (char ch[], int start, int length)
      throws SAXException;

    public void processingInstruction (String target, String data)
      throws SAXException;

    public void skippedEntity (String name)
      throws SAXException;
  
  }

====================8<====================8<====================

There are three significant advantages to doing things this way:

1. Namespace support is a core and natural part of the interface,
   but non-Namespace processing is still possible with no penalty.

2. There's a lot of compatibility with SAX 1.0, but implementations in 
   other languages won't have to carry around the SAX 1.0 baggage
   (they won't have Parser or DocumentHandler at all).

3. Writing an implementation and SAX1 adapters will be easy enough
   that I might actually get around to doing it.

Comments?  If there is anything approaching agreement (or even
grudging acceptance), I can try to get out a beta this week with SAX1
adapters.


All the best,


David

-- 
David Megginson                 david@m...
           http://www.megginson.com/

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



PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.