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

Posted on 2003-11-30
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 (
LVL 86

Accepted Solution

CEHJ earned 50 total points
ID: 9845060
This might be of use:

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


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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

617 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