[jdom-interest] Performance issues

Philipp Groeschler mailinglists at pealpjpain.net
Thu Aug 21 03:44:38 PDT 2003


Good morning!

The task in my code is the following: I've got a Document object
containing an element tree which was build from a valid xml file. This
element tree is walked through by a recursive method, which in some
cases has to replace the current element it is working on. After two
days of getting nervous on ConcurrentModificationExceptions, the code
works pretty fine, except that it is very slow:

private void transform_document (Element parent_element)
{
  List element_list = parent_element.getChildren ();

  for (int i = 0; i < element_list.size (); i ++)
  {
    Element this_element = (Element) element_list.get (i);

    if (this_element.getNamespace () == orange_namespace)
    {
	//  do something ....
      //  replace old element
      element_list.set (i, new_element);
    }

    transform_document (this_element);
  }
}

The FAQ says, using an Iterator except a List and a for-loop is faster.
But when I use Iterators and the remove-method, the thing throws a
ConcurrentModificationException when I try to attach the new Element.
The Element sequence has to be preserved, so adding the new Elements
after the loop will not work for me.

Are there any other ways to process an Element tree in such way, which
will work faster than this? Does converting the List to an Array help me
out?

Thanks a lot in advance ...

Philipp




More information about the jdom-interest mailing list