I know it can be done the way you recommend below but what I like about
dom4j is the elegance in which you can manipulate an XML resource.  With 4
lines of clean dom4j code you could replicate what takes 12 lines of W3C DOM
code.  I'm fully aware than creating and maintaining an API is the ultimate
balancing act between necessity and want because what you want you may not
need.  So far dom4j has done an excellent job in striking that balance and I
don't want to be the one to throw it off.  Therefore, I would prefer if my
request is approved or denied by the developers and users based upon a
consensus that the Node interface should have a hasChildren method instead
if does it make Dane's life easier.

Dane Foster
Equity Technology Group, Inc
http://www.equitytg.com.
954.360.9800
----- Original Message -----
From: "James Strachan" <[EMAIL PROTECTED]>
To: "Dane Foster" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
Sent: Tuesday, July 03, 2001 11:04 AM
Subject: Re: [dom4j-user] request for a method


Hi Dane

From: "Dane Foster" <[EMAIL PROTECTED]>
> I have a recommendation for a new method to be added to the org.dom4j.Node
> interface:
> public boolean hasChildren().
>
> hasChildren should return true if this node has children and false if it
> doesn't.  The reason for this request is, if you are creating a tree
walking
> class hasChildren simplifies the process of figuring out how deep the
> nesting of nodes go.  If anyone needs justification via code sample I will
> gladly whip one up.

Just a thought, how about this:-

Node node = ..;

boolean hasChildren = false;
if ( node instanceof Branch ) {
    Branch branch = (Branch) node;
    hasChildren = branch.nodeCount() > 0;
}

The same thing could be done in one line of code (albeit a bit messy)

if ( node instanceof Branch && ((Branch) node).nodeCount() > 0 ) {
    // I have children...
}

Would having the hasChildren() make your code much simpler?

James


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com




_______________________________________________
dom4j-user mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/dom4j-user

Reply via email to