[jdom-interest] Element Reference from Attribute

Elliotte Rusty Harold elharo at metalab.unc.edu
Mon Nov 20 05:02:39 PST 2000


At 10:10 AM -0800 11/19/00, Jason Hunter wrote:

>>  3. A Node interface or superclass would be a good thing.
>
>Could you provide more detail about how you would design it?
>

public interface Node {

   public Node   getParent();
   public String getValue();

   // possibly
   public Document getDocument()

}

Possibly we could redefine getParent() like this:

   public Element   getParent();

getParent() on the root element would return null, but getDocument() 
would not. That might be even more useful.

I'm not sure whether a getChildren() method would be useful:

   public List getChildren()

or

   public NodeList getChildren()

If we did add this, I'd propose it return an empty list rather than 
null for non-childbearing nodes. But then that list isn't live and 
some other lists are, which is confusing. So maybe we should just 
leave this method off the interface. Or perhaps define a new 
sub-interface just for Document and Element:

public interface ParentNode extends Node {

   public ParentNode getParent();
   public String     getValue();
   public Document   getDocument()
   public NodeList   getChildren()
   public NodeList   getChildren(String XPathQuery)
   // etc.

}
-- 

+-----------------------+------------------------+-------------------+
| Elliotte Rusty Harold | elharo at metalab.unc.edu | Writer/Programmer |
+-----------------------+------------------------+-------------------+
|                  The XML Bible (IDG Books, 1999)                   |
|              http://metalab.unc.edu/xml/books/bible/               |
|   http://www.amazon.com/exec/obidos/ISBN=0764532367/cafeaulaitA/   |
+----------------------------------+---------------------------------+
|  Read Cafe au Lait for Java News:  http://metalab.unc.edu/javafaq/ |
|  Read Cafe con Leche for XML News: http://metalab.unc.edu/xml/     |
+----------------------------------+---------------------------------+



More information about the jdom-interest mailing list