[prev in list] [next in list] [prev in thread] [next in thread] 

List:       xerces-j-dev
Subject:    Re: Attribute parameter scope limited to ContentHandler.startElement
From:       Michael R MR Glavassevich <mrglavas () ecemail ! uwaterloo ! ca>
Date:       2003-01-26 21:39:52
[Download RAW message or body]

Hello Scott,

I noticed this behaviour in the parser awhile ago. For each SAX parser
instance, there exists only one XMLAttributes instance which is reused for
every new set of attributes. So, on each startElement() call, the previous
values in this object will have been overwritten.

SAX doesn't specify scoping rules for Attributes. Though users may not
expect the current bevhaviour, I'm assuming that this behaviour was an 
implementation decision to reduce object creation. If you need to persist
Attributes beyond startElement(), as a workaround you could mine the
object, and store its contents elsewhere. You can do this easily with
org.xml.sax.helpers.AttributesImpl, which can be used to copy the contents
of another Attributes object.

On Sun, 26 Jan 2003, Scott Goldstein wrote:

> During the startElement() method in a ContentHandler implementation, I store a 
> reference to the Attributes parameter and later attempt to use it in 
> endElement().  What I experience in endElement(), however, is that the 
> variable no longer contains the same data.  It now contains data of another 
> element.
> 
> The javadocs do not state that the Attributes parameter is scoped to only 
> startElement().  Is this a bug?
> 
> Thanks.
> 
> Scott
> 
> ------------------------------------------------------------
> "Just a mirror for the sun...
>  My smiling eyes are just a mirror for the sun."
> ------------------------------------------------------------
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-j-user-help@xml.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic