Java Mailing List Archive

http://www.junlu.com/

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

[jdom-interest] Strange Element.addContent(index,Content) problem

Kai Woerner

2004-03-24

Replies:

Hi all...

I just reconginzed that I'm too stupid to send my answers to the mailing
list, so i thought I'll let you know how my problem was solved:

It turned out that I had mixed content due to whitespace in my document
(still don't know where that comes from) that kept me from getting the
right index; suggestions for a solution included using
elmt.getChildren().add("one") (which doesn't help, since it adds the
content at the end of the whole content, not behind the last "one"
child). I came out using the following code:

if (elmt.getChildren("two").size() > 0) {
  myIndex = elmt.getContent().indexOf(elmt.getChild("two"));
} else {
  myIndex = elmt.getContentSize();
}
elmt.addContent(myIndex,newElmt);

(as a reminder: i want to add an element "one" behind the last element
"one" in a list like <one /><one /><two /><two />, whether there's
whitespace somewhere or not)
This works for now, but I'm still wondering if there's a more
straightforward solution (like elmt.addBeforeChild("two") or something
like that - or is my scenario really that uncommon?

Kai W�rner



_______________________________________________
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.