[jdom-interest] Comment and ProcessingInstruction parents
Elliotte Rusty Harold
elharo at metalab.unc.edu
Thu Apr 18 08:32:21 PDT 2002
The Comment and ProcessingInstruction classes appear to be deeply
schizophrenic about who can be their parents, specifically whether or
not a Document is allowed as a parent of one of these. (This is legal in
normal XML temrinology. A typical xml-stylesheet processing instruction
in the prolog would be considered to have the document itself as its
parent.)
For example, in ProcessingInstruction the parent field is declared to
have type Object:
/** Parent element, document, or null if none */
protected Object parent;
However, setParent() and getParent() only allow elements as parents:
/**
* <p>
* This will return the parent of this
<code>ProcessingInstruction</code>.
* If there is no parent, then this returns <code>null</code>.
* </p>
*
* @return parent of this <code>ProcessingInstruction</code>
*/
public Element getParent() {
if (parent instanceof Element) {
return (Element) parent;
}
return null;
}
/**
* <p>
* This will set the parent of this <code>ProcessingInstruction</code>.
* </p>
*
* @param parent <code>Element</code> to be new parent.
* @return this <code>ProcessingInstruction</code> modified.
*/
protected ProcessingInstruction setParent(Element parent) {
this.parent = parent;
return this;
}
One of these needs to be fixed, and I think it's setParent() and
getParent(). Processing instructions and comments do appear with the
document itself as the natural parent. We need to support that.
--
+-----------------------+------------------------+-------------------+
| Elliotte Rusty Harold | elharo at metalab.unc.edu | Writer/Programmer |
+-----------------------+------------------------+-------------------+
| The XML Bible, 2nd Edition (IDG Books, 2001) |
| http://www.cafeconleche.org/books/bible2/ |
| http://www.amazon.com/exec/obidos/ISBN=0764547607/cafeaulaitA/ |
+----------------------------------+---------------------------------+
| Read Cafe au Lait for Java News: http://www.cafeaulait.org/ |
| Read Cafe con Leche for XML News: http://www.cafeconleche.org/ |
+----------------------------------+---------------------------------+
More information about the jdom-interest
mailing list