[jdom-interest] Problem with Jdom8 - getChildren() on root do esn't work...
Beleznay, Dave
Dave.Beleznay at webct.com
Mon Apr 8 15:28:28 PDT 2002
Hi Bradley,
Unfortunately I think i'm having the EJB Serialization problem as well.
(didn't notice that thread before) so I can't really test (in my
debugger rootElement.getChildren() is always returning an empty list),
but I've still got a couple of questions for how it *should* be working,
as I'm not sure i'm reading you correctly...
> // get a 'live' list of rootElement's content, by 'live' we mean
changes
> // it, also show in rootElement and any other 'live' list obtained
from
> // a call to getChildren or getContent on the same element.
getChildren
> // returns a view of the Elements content where only objects of type
> // Element are visiable. Since it is live however,
children.add(someElement)
> // produces the same result as rootElement(someElement).
> List children = rootElement.getChildren();
if I were to do a children.add(someElement) that's the same as
rootElement(someElement)? do you mean
rootElement.addContent(someElement) ?
If I were to write the code the same way :
List children = rootElement.getChildren();
// rootElement.removeChildren();
ListIterator i = children.listIterator();
while (i.hasNext()) {
Element ele = (Element) i.next();
String eleName = ele.getName();
if (eleName.equals("role")) {
i.next();
i.add(roleDesigner);
}
}
rootElement.setChildren(children);
only removing the line to removeChildren(), then the last call to
setChildren is basically doing nothing?
Or should I be creating a new ArrayList and playing with that, as was
suggested?
children = new ArrayList(rootElement.getChildren());
Cheers,
Dave
-------
David Beleznay
Software Engineer
WebCT
> -----Original Message-----
> From: Bradley S. Huffman [mailto:hip at a.cs.okstate.edu]
> Sent: Monday, April 08, 2002 12:29 PM
> To: Beleznay, Dave
> Cc: jdom-interest at jdom.org
> Subject: Re: [jdom-interest] Problem with Jdom8 -
> getChildren() on root
> do esn't work...
>
>
> "Beleznay, Dave" writes:
>
> > Did this ever get resolved?
>
> The part about EJB and a possible serialization problem? Not yet.
>
> > I seem to be having the same problem when
> > I'm trying getChildren() on the root element.
> > the List children contains no elements after the assignment.
>
> He's you code annotated with with what the current design
> should produce and why.
>
> // get a 'live' list of rootElement's content, by 'live' we mean
changes
> // it, also show in rootElement and any other 'live' list obtained
from
> // a call to getChildren or getContent on the same element.
getChildren
> // returns a view of the Elements content where only objects of type
> // Element are visiable. Since it is live however,
children.add(someElement)
> // produces the same result as rootElement(someElement).
> List children = rootElement.getChildren();
>
> // removes all Element children from rootElement, which means
> all items are
> // also removed from List children, rootElement may still
> have content it
> // just won't be a instanceof Element.
> rootElement.removeChildren();
>
> // this produces a iterator where hasNext() initially will
> return false
> // since children is empty
> ListIterator i = children.listIterator();
>
> // hasNext() is false so the loop is never executed
> while (i.hasNext()) {
> Element ele = (Element) i.next();
> String eleName = ele.getName();
> if (eleName.equals("role")) {
> i.next(); // I assume this is a typo, otherwise you
> have 2 next()
> // in a row without a corresponding hasNext()
> i.add(roleDesigner);
> }
> }
>
> // children is empty so this does nothing
> rootElement.setChildren(children);
>
> Little long winded but there seems to be some confussion
> caused by having
> all Lists 'live', guess we need to improve the docs.
>
> Brad
> _______________________________________________
> To control your jdom-interest membership:
> http://lists.denveronline.net/mailman/options/jdom-interest/yo
uraddr at yourhost.com
More information about the jdom-interest
mailing list