[jdom-interest] Comment and ProcessingInstruction parents

Bradley S. Huffman hip at a.cs.okstate.edu
Thu Apr 18 09:24:58 PDT 2002


They can have a Document as a parent (see setDocument/getDocument). This
is a hold over from when they were two seperate fields.  However, getting
rid of setDocument, changing setParent to take a Element or a Document,
and having getParent return a Object makes more sense.

Brad

Elliotte Rusty Harold writes:

> 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



More information about the jdom-interest mailing list