[jdom-interest] new to jdom .. and many questions

Andres March Andres at ehealthcontracts.com
Tue Aug 27 18:59:00 PDT 2002


Regarding question #2, the preferred method would not be asking an element for its next sibling.  You could do this using XPATH (Jaxen) but I think it would be better to use the list that the element resides in as a child of its parent.  This would be done by calling getChildren on the parent element which returns you the list.  Then it is simply a matter of iterating through the list to find the next element.

Your first question is strange and I am confused by its purpose.  Is an element last, if it is the last child of the last element?  I would argue no because the other elements have not been closed yet and, therefore, could have more content (other than elements).  Regardless, you would like to know about this special characteristic, so I would probably use the same approach I give for your 2nd question for the entire document.  What I mean is that you have the whole document in memory and you can use the list that hold content and determine if it is the last by setting flags for each child list.  When there are no more inner lists you know that you have found your element.

ANDRES MARCH
LEAD APPLICATION DEVELOPER
eHEALTHCONTRACTS, INC.
WWW.eHEALTHCONTRACTS.COM <http://www.eHEALTHCONTRACTS.COM> 
OFFICE: 510.581.5646 x205
MOBILE: 415.999.6735
FAX: 510.582.8013

Note:

The information contained in this message may be privileged and confidential and protected from disclosure. If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify us immediately by replying to the message and deleting it from your computer.

Thank you. eHealthContracts, Inc.



-----Original Message-----
From: Azrael [mailto:azrael at azrael-uk.f2s.com]
Sent: Tuesday, August 27, 2002 5:56 PM
To: jdom-interest at jdom.org
Subject: [jdom-interest] new to jdom .. and many questions


Just joined the list, and thought I'd jump in at the deepend.

I'm working on a project for my MSc to write up an XML compression
algorithm theorised by my supervisor... and I did so without too much
attention to actual manipulation of the XML file .. and instead wrote a
simple xml interface providing the methods I needed to have access to.
Now theoretically (from a lot of manual testing) the algorithm works ..
however to get it to work practically I have to attach my xml interface
onto something real.. which as I have some time left over.. I have 
decided to attempt.
JDOM looks to be almost perfect.. and I admit I haven't spent too much
time looking at it in depth.. but I am sure to be having quite a few
questions on how to do things in order to have jdom functionality under
the hood of my xml classes.

Ok.. so here's my first question:

assuming I have a 'pointer' to the current element:
org.jdom.Element currentElement = <whatever>

and I move up and down the structure with getChild() and getParent()

I would like to implement a method that does:

public boolean hasMoreElements()

basically how it would work, is that if this element is the very last 
element in the whole dom tree, it returns false, otherwise true.
I'm not totally sure how to check this.... it isn't sufficient to have 
no children.. the parent also needs to have no more children.. and the 
parent needs to be the last child ot its parent.. and so on..
am I thinking along the wrong lines? Can anyone suggest a way in which I 
can do this within jdom?

Closely associated with this problem, is my next question, I want a 
method that does:

public Element getNextElement()

this would not return the first child of the currentElement, but instead 
will return currentElements parents _next_ child.
And if currentElement is the final child of its parent, return the first 
child of my parents first child.
basically navigating the dom tree in a breadth first way.

             1
          2  3  4
        5  6  7  8
      9  10 11 12 12

Again, can anyone suggest the best way of doing this?

-- 
                  Azrael

             ("\''/").___..--'''"-._
             `0_ O  )   `-.  (     ).`-.__.`)
             (_Y_.)'  ._   )  `._ `. ``-..-'
           _..`--'_..-_/  /--'_.' .'
          ((i).-''  ((i).'  (((.-'

Of all God's creatures there is only one that cannot be made the slave
of the lash. That one is the cat. If man could be crossed with a cat it
would improve man, but it would deteriorate the cat.

ICQ#52944566


_______________________________________________
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