[jdom-interest] Fw: SAX Proposal: new AttributesBuilder interface

James Strachan james at metastuff.com
Mon Nov 20 05:57:55 PST 2000


I thought I'd post this here too in case anyone is interested. I sent it to
the xml-dev to a flurry of, erm, one response. :-(
 
<motivation>
Right now a SAX parser uses its own internal data structure to implement the
SAX Attributes interface. Higher levels above SAX often want to use their
own data structure to store attribute information. For example to allow them
to be mutable. This often leads to unnecessary conversion from one data
structure to another.
 
A good example is JDOM ( http://www.jdom.org <http://www.jdom.org> ) which
takes the SAX Attriibutes object and builds its own List of Attribute
objects to represent its attribute information. This copying from an
Attributes instance to a different data structure is needless redundancy.
 
This proposal attempts to put in place a simple mechanism by which
"attribute data structure duplication" can be avoided.
</motivation>
 
<proposal>
Consider the following new interface.
 
public interface AttributesBuilder {
 
    /** creates an empty Attributes instance */
    public Attributes createAttributes();
 
    /** @return a possibly different Attributes instance
      * which has the new attribute added */
    public Attributes addAttribute ( Attributes attributes,
        String localName, 
        String namespacePrefix, 
        String namespaceURI, 
        String type, // e.g. CDATA 
        String value
    );
}
 
The above interface abstracts away the creation of a new Attributes
implementation and adding of individual attribute instances to it. Let us
also make a change to the XMLReader class then has a new method added to
it:-
 
public interface XMLReader {
    ...
    public void setAttributesBuilder( AttributesBuilder );
}
 
The implementation of XMLReader will come with a standard implementation of
AttributesBuilder. But this new interface and method allows users of the
XMLReader to override how to build an Attributes instance to use a more
applicable data structure.
So JDOM could build the List of Attribute instances it wants, providing it
implements the Attributes and AttributesBuilder interefaces correctly.
</proposal>
 
<implications>
The SAX API gets one new interface and one new method.
 
parser/XMLReader implementors need to implement the new
interface.</implications>
<implications>
 
<issues>
are the arguments for the AttributesBuilder.addAttribute() correct? Will
this new API cause problems for the parser writers?
</issues>
 
Thoughts?
 
 
J.
 
James Strachan
=============
email: james at metastuff.com <mailto:james at metastuff.com> 
web: http://www.metastuff.com <http://www.metastuff.com> 



If you are not the addressee of this confidential e-mail and any
attachments, please delete it and inform the sender; unauthorised
redistribution or publication is prohibited. Views expressed are those of
the author and do not necessarily represent those of Citria Limited.



More information about the jdom-interest mailing list