Element[] roots = doc.getRootElements(); int size = 0; int rootSize = roots.length;   for (int i = 0; i < rootSize; i++) size += roots[i].getElementCount() + 1;  Element[] elements = new Element[size];   for (int j = 0; j < rootSize; j++) elements[j] = roots[j];   for (int k = 0; k < rootSize; k++) { Element current = roots[k]; elements[k] = current.getElement(current.getElementIndex(offset)); }  return elements;
return getElementsAt(doc.getDefaultRootElement(), offset, 0);
      protected Element[] getElementsAt(HTMLDocument doc,                                        int offset)      {        // More efficent than using a Vector        Element[] roots = doc.getRootElements();        int size = 0;        int rootSize = roots.length;                // Get total size        for (int i = 0; i < rootSize; i++)          size += roots[i].getElementCount() + 1;                Element[] elements = new Element[size];                // Add all roots to the array first        for (int j = 0; j < rootSize; j++)          elements[j] = roots[j];                // Add all the children of the roots        for (int k = 0; k < rootSize; k++)          {            Element current = roots[k];            elements[k] = current.getElement(current.getElementIndex(offset));          }                return elements;      }