[XML-SIG] saxlib and enumerations

Paul Prescod papresco@technologist.com
Mon, 16 Mar 1998 18:13:54 -0500


Okay, I've translated a Java SAX program to Python to make sure that our
interface is the same as theirs. After some fiddling with my JPython
installation, I successfully parsed an XML document based on a Java
parser (Microstar's AELFred). I was hoping to be able to be able to
parse using Python programs with no change, but failed in my first test,
with xmllib.py and xlsax.py.

Here's what my Java-trasnlated code to handle attributes looks like:

	attNames = atts.getAttributeNames()
	while (attNames.hasMoreElements()):
      		aname = attNames.nextElement()
		...
attNames is a Java "enumeration object". Of course the Python equivalent
is a sequence. So the code would look like this if I was using a Python
parser:

	attNames = atts.getAttributeNames()
	for (aname in attNames.hasMoreElements()):
		...

I can think of three ways to address this:

 #1. We could abandon the idea of using Java parsers directly in
JPython, and always require a thin "wrapper" that translates Java
enumerations to Python sequences.

 #2. We could ask Jim to wrap *all* Java enumerations in Python
sequences.

 #3. We could port the Java "enumeration" concept to Python for use with
saxlib.

 Paul Prescod  - http://itrc.uwaterloo.ca/~papresco

"You have the wrong number."
"Eh? Isn't that the Odeon?"
"No, this is the Great Theater of Life. Admission is free, but the 
taxation is mortal. You come when you can, and leave when you must. The 
show is continuous. Good-night." -- Robertson Davies, "The Cunning Man"