[jdom-interest] Comment and ProcessingInstruction parents
Elliotte Rusty Harold
elharo at metalab.unc.edu
Sat Apr 5 19:14:58 PST 2003
I'm repeating this suggestion from April. At the time Bradley
Huffman, agreed that it was a good idea. I don't think anyone else
commented one way or the other. I've implemented this for Comment. It
would be hard to implement it for the other classes.
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/
|
+----------------------------------+---------------------------------+
_______________________________________________
To control your jdom-interest membership:
http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost.com
--
+-----------------------+------------------------+-------------------+
| Elliotte Rusty Harold | elharo at metalab.unc.edu | Writer/Programmer |
+-----------------------+------------------------+-------------------+
| Processing XML with Java (Addison-Wesley, 2002) |
| http://www.cafeconleche.org/books/xmljava |
| http://www.amazon.com/exec/obidos/ISBN%3D0201771861/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