Attribute parameter scope limited to ContentHandler.startElement 2003-01-26 - By Michael R MR Glavassevich
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@(protected) > For additional commands, e-mail: xerces-j-user-help@(protected)
--------------------------------------------------------------------- To unsubscribe, e-mail: xerces-j-user-unsubscribe@(protected) For additional commands, e-mail: xerces-j-user-help@(protected)
|
|