xml-general mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Dane Foster" <dfos...@equitytg.com>
Subject Re: Problem with Attributes
Date Tue, 23 Jan 2001 20:59:16 GMT
Dave wrote
"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?"

You can and you can't.  It depends on the parser.  Xerces-J will allow you
to use the Attributes parameter after the method returns.  My original
problem occurred because I wasn't using Xerces-J, I was using the Aelfred
parser (properties file mix-up).  Aelfred immediately removes all attributes
after the start element returns.  Thank the code Gods for open source
because it would have taken me a while to figure it out if there was no
source code available for me to read.

Thanx for the rapid response.


Dane Foster
Equity Technology Group, Inc
http://www.equitytg.com.

----- Original Message -----
From: <David_N_Bertoni@lotus.com>
To: <general@xml.apache.org>
Sent: Tuesday, January 23, 2001 2:42 PM
Subject: Re: Problem with Attributes



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?

Dave




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





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
describing
}

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
http://www.equitytg.com.




---------------------------------------------------------------------
In case of troubles, e-mail:     webmaster@xml.apache.org
To unsubscribe, e-mail:          general-unsubscribe@xml.apache.org
For additional commands, e-mail: general-help@xml.apache.org




Mime
View raw message