[jdom-interest] new to jdom .. and many questions
azrael at azrael-uk.f2s.com
Tue Aug 27 19:06:20 PDT 2002
Of course, you're very much correct regarding my first question.. it's
late and I wasn't thinking straight :)
I badly explained with extra detail what would have been simpler with a
shorter question.. of how to find if it was the very last element or not.
I don't really want to be learning to use XPATH in java right now.. and
so will go for the iterating method you suggest..
finding next sibling as you say is easy enough.. but I am a little
unsure about how to navigate the jdom tree breadth first using the
Lists.. does anyone have example code that I could use as a guide?
`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.
Andres March wrote:
>> 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.
> Ok.. so here's my first question:
> 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.
> Again, can anyone suggest the best way of doing this?
More information about the jdom-interest