xml-general mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David_N_Bert...@lotus.com
Subject Re: Problem with Attributes
Date Tue, 23 Jan 2001 19:42:52 GMT

I don't think you can save a reference to the Attributes parameter in the
startElement() call and expect that the contents will be valid after the
function has returned.  If you want to use the Attributes parameter, you'll
need to do it in the startElement() event.  Perhaps you can clone it?

I'm pretty sure this is a general principle with SAX.  Have you tried
looking at the Attributes during the startElement() call, just to make sure
the values you expect are there?


                    "Dane Foster"                                                        
                    <dfoster@equi        To:     <general@xml.apache.org>       
                    tytg.com>            cc:     (bcc: David N Bertoni/CAM/Lotus)     
                                         Subject:     Problem with Attributes            
                    02:04 PM                                                             
                    respond to                                                           

I'm parsing an XML document using SAX2 and I'm having a bit of trouble
getting data using the Attributes interface.  Here is quick codelet of what
I'm doing:

Note: Assume that the XML document is valid and therefore cannot be the
cause of the error.

// objectStack is a member variable of type java.util.Stack

public void startElement( String a, String b, String c, Attributes atts )
throws SAXException
    if( c.equals( "elementName" ) ) objectStack.push( atts );
    // other if/else statements follows but doesn't affect what I'm

public void endElement( String a, String b, String c ) throws SAXException
    if( c.equals( "elementName" ) )
        Attributes att = (Attributes)objectStack.pop();

        String var1 = att.getValue( "variable_one" );
        String var2 = att.getValue( "variable_two" );

The problem is att.getValue( "param" ) returns null so when I go to use
var1 and/or var2 a NullPointerException is thrown.  Any help would be
greatly appreciated.

Dane Foster

View raw message