[jdom-interest] How to replace an Element with Text?
Bradley S. Huffman
hip at cs.okstate.edu
Sun Mar 28 08:15:05 PST 2004
Brad Cox writes:
> Thanks! That was exactly the problem. But the solution still eludes.
>
> After rewriting like this: (no such class as Parent, and Element
> doesn't do indexOf()):
>
> Element parent = e.getParent();
> List siblings = parent.getChildren();
> int index = siblings.indexOf(e);
> Text t = new Text("#radioElement('"+nameAttr+"'
> '"+valueAttr+"' '"+buf+"')");
> siblings.set(index, t);
>
> I get this error:
> org.jdom.IllegalAddException: Filter won't allow index 0 to be set to
> org.jdom.Text at
> org.jdom.ContentList$FilterList.set(ContentList.java:835)
> Looks like JDOM is onto this and is determined to stop it. Time for
> bigger hammers? ;)
Skip using getChildren which gives a filtered view of only Elements and use
the indexOf defined on Element.
Element parent = e.getParent();
int index = parent.indexOf(e);
Brad
Go Pokes!!!
More information about the jdom-interest
mailing list