[XML-SIG] SAX Namespaces

Paul Prescod paul@prescod.net
Thu, 06 Jul 2000 11:04:00 -0500


Greg Stein wrote:
> 
>   iv)  {(URI, localname) : (qname, value), ...}
> 
> Using (iv) means that the passed attribute dictionary is immediately usable.
> The other forms require some initial processing, yet provide no value-add.

It is immediately usable as a dictionary, but it must be converted to a
list for apps that want to iterate over attributes. Examples include
canonizers, tree builders, pretty printers and so forth. Here's the
first line of qp_xml dealing with attributes:

>    for name, value in attrs.items():

Minidom uses the same first line, and so do a bunch of our other sample
programs.

Here are my reasons for preferring a list to a dictionary, from most
important to least:

1. Many (most?) apps turn the dictionary into a list immediately.

2. Those that want "lookup" capability might want (URI,name)-based
lookup,  qname-based lookup, or both. The AttributesList interface
provided both.

3. Dictionary building and populating is more expensive than list
building.

4. Attribute lists are typically so small (two or three items) that it
is debatable whether a hashtable is the right index structure for them
anyhow. Maybe linear search is better for a lot of apps. Maybe "lazy"
indexing is better. I'd rather leave it up to the app.

5. Pyexpat delivers the attributes as a list. Python 1.7 might just wrap
the pyexpat data structure as a sequence rather than copying the
attributes out (admittedly, more research is needed...!)

6. Bundling the qname with the value is not that intuitive.

I vote for:

>   ii)  [(((URI, localname), qname), value), ...] 


-- 
 Paul Prescod - Not encumbered by corporate consensus
The distinction between the real twentieth century (1914-1999) and the
calenderical one (1900-2000) is based on the convincing idea that the 
century's bouts of unprecented violence, both within nations and between 
them, possess a definite historical coherence -- that they constitute,
to 
put it simply, a single story. 
	- The Unfinished Twentieth Century, Jonathan Schell 
		Harper's Magazine, January 2000