AttributeMap (was Re: Announcement: SAX 1998-01-12 Draft)

Matthew Gertner matthewg at poet.de
Wed Jan 14 13:53:08 GMT 1998


James Clark wrote:

>AttributeMap seems way too complicated.
>
>I don't think using Enumeration to get all the attributes is a good
>idea.  JDK 1.2 replaces Enumeration by Iterator.  The method names in
>Enumeration are a real disaster in the context of XML: nextElement
>returns the name of the next attribute!  This is not going to be an
>efficient way to get at all the attributes (which is a common
>application need).  To get at all the attributes, I have first to create
>an Enumeration (an unnecessary allocation). Then for each attribute
>name: I have to make two non-final method calls (nextElement and
>hasMoreElements); I then have a cast (which must be checked) from Object
>to String; I then have to look the attribute up using getValue.  Compare
>this to the simple interface I suggested:
>
>void startElement(String elementName, String[] attributeNames, String[]
>attributeValues, int nAttributes)

I agree that the AttributeMap is too complicated. On the other hand, your
alternate proposal seems questionable. Passing three parameters to the event
handler may be simple, but this eliminates any abstraction, which makes it
hard to extend the interface cleanly. Also, this makes iteration easy but
finding attributes by name very hard.

An AttributeMap interface should be used, but:

1) It should provide a standard iterator interface (this is the only
reasonable way to iterate over a map).
2) It should deliver attributes values as strings (the current getValue)
only. All of the "is" methods seem *way* out of scope for SAX. We decided we
didn't want DOM building capability (or a similar level of functionality),
so why is this information necessary? This spec very accurately represents a
consensus of the various points discussed on the list, but I don't remember
any discussion about getting additional information about the attribute
beyond the value. Did I miss something?

IMHO, the following perfectly sufficient for the time being:

public Iterator getIterator ();
public String getValue (String attributeName);

We might want to consider making the map from a string to an Attribute
object:

public Attribute getAttribute (String attributeName);

The Attribute interface would contain only:

public String getName ();
public String getValue ();

This would make extensibility easier in moving towards an advanced version
of SAX with DOM-building power.

Matthew



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/
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