[XML-SIG] saxlib and enumerations

Stefane Fermigier fermigie@math.jussieu.fr
Tue, 17 Mar 1998 00:26:56 +0100


On Mon, Mar 16, 1998 at 06:13:54PM -0500, Paul Prescod wrote:
> 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()):
> 		...

Attribute maps are currently implement, in either saxlib or PyDOM, 
as dictionnaries, so this would be coded as:

	for aname, avalue in atts.items():

Of course this is not good for other reasons, and should be fixed before
public release.

My point is that I don't want to use a language with sophisticated
builtin data structures like python and just mimic the low-level interface of
a Java library.

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

There is once again the issue of iterators in python that could be raised here.

The #1 solution is the only valid one for the short term.

Cheers,

	S.

-- 
Stéfane Fermigier, MdC à l'Université Paris 7. Tel: 01.44.27.61.01 (Bureau).
Mathematician, hacker, bassist.  http://www.math.jussieu.fr/~fermigie/
"Life is good for only two things, discovering mathematics and teaching 
mathematics." Siméon Poisson.