[XML-SIG] SAX Namespaces

Greg Stein gstein@lyra.org
Mon, 3 Jul 2000 18:10:46 -0700


On Mon, Jul 03, 2000 at 03:33:24PM -0500, Paul Prescod wrote:
> [still catching up]
> 
> > ...
> > I think this is very wrong, and that we shouldn't do it. I've looked
> > through the SAX code in the Python CVS tree and this is the only thing
> > I'm really unhappy about.
> > 
> > Let me enumerate the reasons:
> > 
> >  - the rawname is not really part of the element name, so it does not
> >    feel right to have it in the tuple like that
> 
> The rawname *is* the element type name.

No, the element name is the (namespace, element-name) tuple. The rawname is
actually quite hard to use. We had talked about preserving the namespace
*prefix*. The third item in the provided data should be the bare prefix.

> >  - it makes name comparison (the most common operation on names!)
> >    really ugly:
> >
> >      if name[0] == xslt_ns and \
> >         name[1] == 'template':
> >         # do something useful
> 
> #1. I don't fundamentally believe that people will be doing this at the
> SAX level.

I do it all the time (although I don't use SAX). These kinds of comparisons
are quite common, and I am certainly not going to use some magic tools that
simplify it for me.

To enable comparisions like above, the best output format would be something
like: ((URI, element-name), prefix). This enables people to use name[0] for
the distinguished name (primary key).

> SAX is pretty painful for this sort of thing and I would like
> to see people move to something with a stack and tree mode (whether
> pulldom, Pyxie, whatever) soon.

Don't tell me, or others, where to move our code, our designs, or our
algorithms. It is not your place to legislate.

> #2. The clean way to do what you describe is:
> 
> def startElement( self, (URI, name, rawname), attrs ):
>     if (URI, name)==xslt_ns
>         # do something useful
> 
> or:
> 
> def startElement( self, name, attrs ):
>     (URI, localname, rawname)=name
>     if (URI, localname)==xslt_ns
>         # do something useful

or:
  def startElement(self, name, attrs):
      if name == xslt_ns:
          # do something useful

or:
  def startElement(self, ((URI, name), prefix), attrs):
      if URI != 'DAV:'
          return
      # do something useful

Both of your alternatives constructed a tuple at *runtime*. I'd rather avoid
the tuple construction and keep the (IMO) cleaner model.

>...
> >  - it makes it harder to make people understand that the prefix used
> >    in the XML document is not part of the element name
> 
> Namespaces are complicated and nasty. The old SAX API did not change
> that.

They don't have to be. I've never had a problem with them in my qp_xml
module or the users of that module.

> >  - I don't see anything that is made easier or faster by this
> >    representation
> 
> The DOM, XPath and XSLT-based APIs will need the URI, localname, rawname
> triple (or at least URI/rawname).

Not the rawname... the prefix. Combining the prefix/name means that somebody
must then yank it bank apart to deal with that prefix. When they arrive
seperate, then the developer has an easy choice for putting them back
together.

> It would be nice to pass the same
> tuple from Pyexpat->SAX->... with no rebundling. In fact, I hope to
> optimize the SAX layer away altogether. (by making PyExpat a SAX parser
> and minidom et. al. SAX consumers).

Please do not add SAX to the front of pyexpat.c. I always want to have
access to the raw handlers. Expat is known as the *fastest* non-validating
parser around. I don't want to see a bunch of stuff gummed onto the Python
version which kills that speed.

> >  - we already discussed this and decided for something else; I think
> >    we should not change our minds without good reason
> 
> Agreed. We can go back to the way things were easily at this point. My

You should not be making API changes unilaterally. That is totally against
the spirit here. Great, you have commit access. I do, too. Should I go in
and start making API changes because they suit me?

>...
> > Hoping this is not too late...
> 
> No, it isn't too late and I consider SAX your domain. I just did what
> seemed to me to be the best thing for performance when it comes to names
> and I haven't touched AttributeList yet.

I think this discussion needs to be reset, and a new consensus needs to be
reached. There are obviously divergent opinions here.

Can somebody enumerate each of the options here so that we can restart the
discussion?

Cheers,
-g

-- 
Greg Stein, http://www.lyra.org/