[jdom-interest] Element Reference from Attribute

Elliotte Rusty Harold elharo at metalab.unc.edu
Mon Nov 20 04:43:56 PST 2000

At 3:49 PM -0500 11/19/00, bob mcwhirter wrote:
>>  1. Everything needs to know its parent. I don't really care if that
>>  adds 4 bytes to each object.
>>  2. Using Strings instead of a Text class is extremely inconvenient.
>>  3. A Node interface or superclass would be a good thing.
>I heartily agree with 1 && 2, of course.
>What methods do you think would be appropriate for Node, or would
>it simply be a hollow class/interface, for generic method signatures?

The Node interface should have methods to get the parent and the 
value of the node. I propose that the "value" of the Node be 
determined by the XPath definition of value rather than the DOM 
definition of value. This way the value of al element is the text of 
the element rather than null.

However, the main reason I want a Node interface is for return and 
argument types. There are a lot of methods where I find I'm forced to 
pass or return Object simply because there's no other common type for 
XML nodes. For instance, in XInclude an element can be replaced by an 
element, a String, a group of elements, or a group of elements and 
strings. Thus my resolve method is declared like this:

public Object resolve(Element e)

I'd like it to be declared like this:

public Node resolve(Element e)

or perhaps:

public NodeList resolve(Element e)

There are a lot of other places in the JDOM API where you're allowed 
to do weird things like insert a Frame or a Socket into an XML 
document because we're using Object as the common superclass. 
Sometimes this doesn't even throw an exception! Even if we don't 
define a Node interface, I think we need to redefine PartialList so 
that it won't allow types to be inserted in the list that simply 
don't belong there.

| 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