[jdom-interest] isRootElement issue

Kesav Kumar kesavk at voquette.com
Tue Oct 24 09:37:04 PDT 2000


Actually I was developing a Swing TreeModel based on JDOM structure during I
found some intersting behaviour(misbehaviour) of isRootElement.  The weared
situation is like this.  

			Element root = new Element("Root");  //Root Element
			Document doc = new Document(root);   //I create
			Element tmp = new Element("Temp");   //Temporary
element
			root.addContent(tmp);                //Adding tmp
element to root
			List content = root.getMixedContent(); //Get the
whole contetn
			Element child = new Element("Child");  // New child
			Document doc1 = new Document(child);   // New
Document
			content.set(content.indexOf(tmp),
doc1.getRootElement());  //Replacing temp node with child(No errors)
			System.out.println(child.isRootElement());  //Gives
true


This is just a dirty example of creating bad JDOM structure but in reality I
had the same situation where I need to use the set method which can accept
any Element.  In my actual case I covert text to Document and Element to
Text so when ever I convert text to Document it gives me Element associated
with document(SAXBuilder) then the whole tree is breaking.

Sorry for the offtrack.  


Kesav Kumar
Software Engineer
Voquette, Inc.
650 356 3740
mailto:kesavk at voquette.com
http://www.voquette.com


-----Original Message-----
From: Jeremy Howard [mailto:jeremyh at flashcom.net]
Sent: Monday, October 23, 2000 11:59 PM
To: jdom-interest at jdom.org
Subject: Re: [jdom-interest] isRootElement issue


On Mon, 23 Oct 2000, you wrote:
> > > Ideally I feel root.isRootElement should return true sice it
> > > has a child.
> >
> > Just because you have a child doesn't mean you're the root.  A root
> > element is the single element directly held by a document.  This is what
> > isRootElement() tests for.
> >
> > -jh-
> >
> 
> Maybe a better name for the method could be isDocumentRoot () ?
> 
> Guy
> 
> >
> > _______________________________________________
> > To control your jdom-interest membership:
> >
>
http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhos
> t.com
> >
> 
> _______________________________________________
> To control your jdom-interest membership:
>
http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhos
t.com


I think isRootElement() is correct just as it is. Since the "Root" element
is
always the element held by a Document.   A more reasonable method would be
isParent() for any node that has children.

Jeremy Howard
jeremyh at flashcom.net
_______________________________________________
To control your jdom-interest membership:
http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhos
t.com



More information about the jdom-interest mailing list