Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Sax Parsers - Attributes object lifetime!!!!! >:(

Posted on 2003-11-30
Medium Priority
Last Modified: 2013-11-23
This is related to the project I've been working on here:
Guess this is will be more of a rant than anything else...  I came up with a great idea for my swing markup language - I previously had 2 arrays of interfaces; the first was called from the startElement(), and it created each object according to the attributes specified.  The second was used in endElement();  this one only dealt with filling container objects such as combos or panels -  by the time the end element tag of the container was reached, all the objects that belonged to the container were already constructed.

I thought that if I could just tag the Attributes object and place it onto my stack(instead of the complete object), I could put off constructing the object until the end tag was reached - thereby reducing my number of anonymous interface classes by the number of container tags (11)...  I would be able to combine the two function tables.

UNFORTUNATELY, the lifetime of the Attributes object seems to end when the startElement() function returns...  When I pop it from the stack in endElement(), it's empty....

_?_ tag      title           hashcode       attr.getLength()
begin: XMLWINDOW    -2093412697     0
begin: menubar  950367828       0
begin: menu     3347807            1
begin: menuitem -603141902      1
end: menuitem   -603141902      0
begin: menuitem -603141902      1
end: menuitem   -603141902      0
end: menu       3347807             0
begin: menu     3347807            1
end: menu       3347807            0
end: menubar    950367828     0
begin: content  951530617       0
begin: desktop  1557106716      0
begin: internal 570410685       5
begin: panel    106433028       2
begin: label    102727412       1
end: label      102727412        0
begin: check    94627080        2
end: check      94627080         0
begin: radio    108270587       2
end: radio      108270587       0
end: panel      106433028      0
end: internal   570410685      0
end: desktop    1557106716   0
end: content    951530617     0
end: XMLWINDOW  -2093412697  0

Now I'm going to have to copy it or something...  This really sux!!!!!!!!!
Question by:ShawnCurry
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +1
LVL 92

Expert Comment

ID: 9844799
you could use a different parser implementation.
LVL 15

Expert Comment

ID: 9844919
If you want to read in the entire XML file before starting to create your objects, you could use DOM instead of SAX.  If you're going to do that, I would recommend using JDOM (http://www.jdom.org).
LVL 86

Accepted Solution

CEHJ earned 200 total points
ID: 9845060
This might be of use:
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.


Author Comment

ID: 9845340
Huh..   That swixml is really close to what i have...  Mine's structured a little differently..

I originally implemented this with a DOM parser...  I moved to a SAX implementation because it was supposed to be faster; and it IS noticably faster.

Using another parser implementation had occurred to me..  Any good tutorials out there??


LVL 86

Expert Comment

ID: 9845354
In your previous question, I mentioned the commons Digester. That also uses SAX. There's all the source and good docs for it. It works by using matching rules based on XPath in order to decide which objects are created as children of what. Very flexible. Although not primarily designed for GUIs, probably could be quite easily used for them.
LVL 92

Expert Comment

ID: 9846417
Nice and light and you can tweak it to your exact requirements.

Author Comment

ID: 9918524
I did find the solution.. just had to read the source code.  I checked to see if it was a known bug, and they said it wasn't a bug..  They do provide a default implemention of the Attributes interface - AttributesImpl - with a copy constructor, in case you need to save the Attributes...

It's moving along nice..  I mapped to almost 60 of the KeyEvent.VK_CONSTANTS to implement accelerator keys for my menus.  I'm also parsing the title for a mnemonic key..  I had to use @ though - xml already uses the ampersand..  32 tags and 25 attributes..

Almost through my 4th iteration.. back up to 2 function tables - tags and attributes.. BUT - I'm down to 6 if statements ;).. That's no joke, I just counted em..   Heh figure that one out.

Thanks for the link..

Featured Post


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question