Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » JDOM User »

Re: [jdom-interest] How to replace an Element with Text?

Bradley S. Huffman

2004-03-28

Replies:

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!!!
_______________________________________________
To control your jdom-interest membership:
http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@(protected)
©2008 junlu.com - Jax Systems, LLC, U.S.A.