Skip to Content.
Sympa Menu

xom-interest - Re: [XOM-interest] checkDetach vs. checkRemoveChild

xom-interest AT lists.ibiblio.org

Subject: XOM API for Processing XML with Java

List archive

Chronological Thread  
  • From: Elliotte Rusty Harold <elharo AT metalab.unc.edu>
  • To: xom-interest AT lists.ibiblio.org
  • Subject: Re: [XOM-interest] checkDetach vs. checkRemoveChild
  • Date: Wed, 10 Mar 2004 04:18:50 -0500

At 11:38 PM -0500 3/9/04, John Cowan wrote:


I'd like there to be a way for any attempt to add a ParagraphElement
to an HTMLElement to introduce a BodyElement between them, but
the check methods can't accomplish that.


Would adding checkAttach solve that problem? Suppose we have this:

HTMLElement html = new HTMLElement();
PElement p = new PElement();
html.appendChild(p);

We could fix this in checkInsertChild like so:

protected void checkInsertChild(Element child) {

if (child instanceof PElement) {
BodyElement body = new BodyElement();
appendChild(body);
body.appendChild (child)
}
throw new XMLException();

}

Gaak. That's ugly. I don't like the side effects or throwing the exception here, but I think that should work.

Can we do the same in checkAttach()? Let's see:

protected void checkAttach(ParentNode parent) {

if (parent instanceof HTMLElement) {
BodyElement body = new BodyElement();
parent.appendChild(body);
body.appendChild(this);
}
throw new XMLException();

}

Still ugly, but not significantly different than the checkInsertChild
solution.
--

Elliotte Rusty Harold
elharo AT metalab.unc.edu
Effective XML (Addison-Wesley, 2003)
http://www.cafeconleche.org/books/effectivexml
http://www.amazon.com/exec/obidos/ISBN%3D0321150406/ref%3Dnosim/cafeaulaitA




Archive powered by MHonArc 2.6.24.

Top of Page