[XML-SIG] Efficient Namespace Handling

Paul Prescod paul@prescod.net
Fri, 30 Jun 2000 10:44:04 -0500


[still having Internet problems...I probably won't get replies
immediately]
---
The various APIs all have well-defined ways for handling namespaces of
elements and attributes. I want to describe a simple data structure for
passing namespace information between APIs. I want it to be as efficient
as possible.

In namespace mode PyExpat should produce tuples: (URI, localname,
rawname)

Those should be passed as the "name" parameter to SAX event handlers of
the form:

def startElement((URI,localname,rawname), attrs):...
	...

Those can in turn be passed to the DOM createElement method which can
check the type of its first parameter and "do the right thing" when it
is a tuple. This is more efficient than the DOM's createElementNS method
which requires string manipulations.

---
The second issue is an efficient way to pass around attributes. Note
that I am not talking about how to query or fetch attributes. Just how
to pass them around. The obvious representation for an attribute value
is ((URI,localname,rawname),value). Tuples and list are much, much
faster to create than instances in Python. Java doesn't really have
equivalents. I propose that in beta 2 of Python, PyExpat in namespace
mode should pass list structures of the form:

[((URI,localname,rawname),value),...] 

I choose not to use dictionaries because it isn't clear whether to index
on rawnames or localname/URI tuples. It depends on the application so it
is better to build dictionary-based indexes at the application level.

If a particular user wants a more friendly data structure they can
construct a DOM AttributeList object:

def startElement((URI,localname,rawname), attrs):...
	attrs=xml.dom.AttributeList( attrs )

(as an optimization, AttributeList objects would probably be lazily
indexed based on either qname or URI/localname, depending on what the
user asked for)
-- 
 Paul Prescod - Not encumbered by corporate consensus
The calculus and the rich body of mathematical analysis to which it 
gave rise made modern science possible, but it was the algorithm that 
made the modern world possible.
	- The Advent of the Algorithm (pending), by David Berlinski