xom-interest AT lists.ibiblio.org
Subject: XOM API for Processing XML with Java
List archive
Re: [XOM-interest] Node hierarchy does not prevent cycles
- From: Elliotte Rusty Harold <elharo AT metalab.unc.edu>
- To: "McEniry, Michael" <mmceniry AT itsc.uah.edu>
- Cc: xom-interest AT lists.ibiblio.org
- Subject: Re: [XOM-interest] Node hierarchy does not prevent cycles
- Date: Fri, 12 Sep 2003 16:28:30 -0400
The node hierarchy does not prevent cycles
(aka "I'm my own grandpa").
The simplest example is:
Element a = new Element("a");
a.appendChild(a);
// time passes...
a.toXML(); // causes a StackOverflowError
I think I see what's going on here. Normally appendChild/insertChild check to make sure that the node being inserted does not already have a parent. However, that wouldn't catch this problem. I'll write a unit test and fix this in CVS shortly.
Is there any way to do this without appending the node itself? Hmm, seems like there might be:
a.appendChild(b);
b.appendChild(c);
c.appendChild(a);
This is a problem. It seems like it could require insertChild descend the entire subtree to verify the insertion is OK. Ugly. Does anyone see a simple, fast way to fix this?
--
Elliotte Rusty Harold
elharo AT metalab.unc.edu
Processing XML with Java (Addison-Wesley, 2002)
http://www.cafeconleche.org/books/xmljava
http://www.amazon.com/exec/obidos/ISBN%3D0201771861/cafeaulaitA
-
[XOM-interest] Node hierarchy does not prevent cycles,
McEniry, Michael, 09/12/2003
-
Re: [XOM-interest] Node hierarchy does not prevent cycles,
Elliotte Rusty Harold, 09/12/2003
- Re: [XOM-interest] Node hierarchy does not prevent cycles, John Cowan, 09/12/2003
- <Possible follow-up(s)>
-
RE: [XOM-interest] Node hierarchy does not prevent cycles,
Regier Avery J, 09/12/2003
- RE: [XOM-interest] Node hierarchy does not prevent cycles, Elliotte Rusty Harold, 09/13/2003
-
Re: [XOM-interest] Node hierarchy does not prevent cycles,
Elliotte Rusty Harold, 09/12/2003
Archive powered by MHonArc 2.6.24.