OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[xml-dev] Re: [Sax-devel] Is the SAX NamespaceSupport class broken?

Quoth: "Elliotte Rusty Harold" <elharo@metalab.unc.edu>
> I'd like to use an org.xml.sax.helpers.NamespaceSupport object to keep 
> track of the namesapces in scope at various points in my ContentHandler, 
> which is exactly what I think it's designed to do.

Well, one of its tasks.  It's described as "for use by SAX Drivers",
but the same logic should be used in applications if they are willing
to deal with the quirk you identified:

> OK, simple enough. I need to start a new context for each element. Now I 
> need to add declarations to that context using the declarePrefix() 
> method. However, the information I need to track the declared prefixes 
> are provided by the startPrefixMapping() method, which is called 
> *before* the corresponding startElement() method is called.

I call this a doc bug.  The "you" in the documentation is a parser writer,
for whom it makes a certain degree of sense:  they'll pushContext()
THEN make the startPrefixMapping() callbacks for xmlns* attributes,
then make the second pass over element/attribute names to get the
URIs and localnames, and then finally call startElement().

When the "you" is an application, it's different.  Creating the context
must be done at either of two locations:  startElement(), or else the
first startPrefixMapping().

As David Megginson wrote, the fix is a single flag.  In fact I did a
writeup on NamespaceSupport recently (for a certain SAX2 book :)
where I said exactly that.

I'll provide a fix in the javadoc, and push it out soon after SourceForge
starts talking to me again.  (The SSH services seem to be AWOL this

- Dave