[From nobody Fri Aug 6 17:04:56 2004 Delivered-To: jhunter@collab.net Return-Path: sweiss@aamc.org Received: (qmail 910 invoked from network); 5 Jul 2000 16:03:38 -0000 Received: from wpo.aamc.org (143.220.4.36) by laswell.collab.net with SMTP; 5 Jul 2000 16:03:38 -0000 Received: from aamc.org (U024223.aamc.org [143.220.24.223]) by wpo.aamc.org; Wed, 05 Jul 2000 12:01:48 -0500 Sender: steve Message-ID: <39635C04.2AC314FF@aamc.org> Date: Wed, 05 Jul 2000 12:02:12 -0400 From: Steve Weiss <sweiss@aamc.org> Organization: Association of American Medical Colleges X-Mailer: Mozilla 4.73 [en] (X11; U; Linux 2.2.14-12 i686) X-Accept-Language: en, de, fr MIME-Version: 1.0 To: Gabor Greif <gabor@no.netopia.com> CC: jdom-interest@jdom.org, Jason Hunter <jhunter@collab.net> Subject: Re: [jdom-interest] Entities with inner structure (proposed fix) References: <B5879490-C72A6@192.109.102.124> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Mozilla-Status2: 00000000 I'm not sure if using an abstract base class would be necessary (although it might be a nice design approach), given Gabor's solution. I did a quick hack on SAXHandler.java (I downloaded the latest from CVS and startElement() has moved there from SAXBuilder.java) and Gabor's code seemed to fix the problem. I still don't have things quite working, but that may be a problem with the way I'm using entities. I'm an XML newbie so I may not be doing things quite right. Anyway, I'll keep fooling around with things- I'd be curious to know if anyone else has been able to use entities though. -Steve Gabor Greif wrote: > > I would underline Steve's diagnosis and add one more twist. > The inEntity instance variable has to be updated to mirror the class of > the object on the top of the stack. > > In SAXBuilder.startElement: > > if (atRoot) { > document.setRootElement(element); > stack.push(element); > atRoot = false; > } else { > Object peeked = stack.peek(); > if (inEntity) > { > ((Entity)peeked).addChild(element); > inEntity = false; > } > else > ((Element)peeked).addChild(element); > > stack.push(element); > } > > In SAXBuilder.endElement: > > stack.pop(); > > inEntity = !stack.empty() && stack.peek() instanceof Entity; > > Of course a common (abstract) baseclass to Element and Entity factoring out > their intersection would be the best solution (as suggested by Steve). > > Gabor > > On Wed, Jun 21, 2000 20:49 Uhr, Steve Weiss <mailto:sweiss@aamc.org> wrote: > >I've had trouble trying to use Entities also, and it looks to me like > >there is a problem in SAXBuilder.java. In startElement(), at line 561 > >(beta4 release) there is this: > > > > if (atRoot) { > > document.setRootElement(element); > > stack.push(element); > > atRoot = false; > > } else { > > ((Element)stack.peek()).addChild(element); <<---- throws > >ClassCastException > > stack.push(element); > > } > > > >It looks like the ClassCastException is being thrown when an Entity > >comes off the stack rather than an Element. Looking at these two > >classes, it seems that both could extend some TBD AbstractXmlThing > >class, which might solve this problem (i.e, cast to AbstractXmlThing > >instead of Element). Of course, I could be way off on this. > > > >-Steve > > > >Gabor Greif wrote: > >> > >> I get an exception when parsing something like > >> > >> <tag> > >> &CancelButton; > >> </tag> > >> > >> where CancelButton is an entity that is not string valued but consists > of > >> tag(s): > >> > >> <!ENTITY CancelButton "<pane type=&#x27;Button&#x27;><ostype > >> name=&#x27;id&#x27;>&CancelButtonID;</ostype><string > >> name=&#x22;label&#x22;>Cancel</string></pane>" > > >> > >> I am using JDOM b4. > >> > >> What is the preferred way to use this feature? > >> > >> I would propose that a subclass of Entity would be created in the "tag" > >> Element, that would have a method for parsing the internal structure of > the > >> entity and giving back its constituents. > >> > >> Any ideas? > >> > >> Thanks, > >> > >> Gabor -- Steve Weiss Association of American Medical Colleges (202)828-0428 mailto:sweiss@aamc.org http://www.aamc.org ]